I am testing out RIA services. I put together a RIA Services library and built a custom DomainService (i.e. not an Entity Framework Domain Service). I am accessing the library from a Silverlight app and all is working as expected. I can call the RIA service functions and get the results.
My issue is with pagination. I cannot find anywhere a description of using pagination on a RIA service that uses custom domainServices. My RIA Service is accessing a specialized DAL for access to data (and is not compatible with the Entity Framework). What I have found was an indication to pass the pagination parameters (i.e. page, page size) to a RIA Service function. So I have done just that - created a RIA service function that takes additional parameters for Page [index] and Page size. I am testing this in Silverlight using a DataGrid and a DataPager. The RIA service with the pagination parameters is called (and returns data) and the DataGrid is populated. The problem I'm having is when I go to another page. What is occurring is the RIA service is called twice. The first time with the proper params (i.e. correct page index) then again with a page index of zero). I.e. always resets to first page. I don't understand why this is occurring; I believe I put everything together properly (hopefully). The following is the XAML script:
<riaControls:DomainDataSource
Name="ddsScheduleTemplates"
LoadSize="20"
QueryName="GetPagedScheduleTemplates"
AutoLoad="True"
>
<riaControls:DomainDataSource.DomainContext>
<ds:ScheduleEngineDomainContext/>
</riaControls:DomainDataSource.DomainContext>
<riaControls:DomainDataSource.QueryParameters>
<riaControls:Parameter ParameterName="UserLogonName" Value="admin" />
<riaControls:Parameter ParameterName="UserPassword" Value="admin" />
<riaControls:Parameter ParameterName="Page" Value="{Binding ElementName=dpScheduleTemplates, Path=PageIndex}" />
<riaControls:Parameter ParameterName="PageSize" Value="{Binding ElementName=dpScheduleTemplates, Path=PageSize}" />
</riaControls:DomainDataSource.QueryParameters>
</riaControls:DomainDataSource>
<StackPanel>
<dg:DataGrid
Name="ScheduleTemplatesGrid"
MinHeight="100"
MaxHeight="300"
IsReadOnly="True"
ItemsSource="{Binding ElementName=ddsScheduleTemplates, Path=Data}"
/>
<dg:DataPager
x:Name="dpScheduleTemplates"
PageSize="10"
Source="{Binding ElementName=ddsScheduleTemplates, Path=Data}"
PageIndexChanged="dpScheduleTemplates_PageIndexChanged"
/>
</StackPanel>
I have modified the above script to call the general loading function (GetPagedScheduleTemplates - returns all records) and adjusted the QueryParameters list for the function. The DataGrid loads properly - and pagination works properly.
This confused me - it sort of looked like the DataPager required all data to be loaded in order for it to work properly - but I did a test where I loaded all data on a paged request operation; (i.e. pagination properties setup and calling pagination version of RIA service function) but DataGrid still resets.
Note: I had read that the DataPager requires the return list to be ordered - so I did so - but did not affect operation - paging always reset to page 1 - the following is the return list from the RIA service function newList.ToArray().AsQueryable().OrderBy(x=>x.ScheduleTemplateID)
So; my question is - has anyone seen this behavior - or am I making a horrendous mistake - if so what am I doing wrong?
Peter