1
votes

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

5

5 Answers

1
votes

Once I integrated the Legecay DAL library I mentioned above all was working properly. Review the library - it is easy to use (but there is some reading/review to get up to speed with it). Also make sure your RIA service is properly configured for pagination. From what I have read and found - setting a page size in the pager and domain data source is required for proper operation. The ria service call also requires a count operation (for the specific entity object) also that return the MAX record count (if this is not done then things like you mention may occur -- the domain data source does not know the total records to paginate through -so it may just go the beginning because it does not have enough info -- this is usally apparent because the pager will not show the proper max page count or will show 1 or zero for the max page).

Peter

0
votes

Ok -- well this took some investigation. I was not aware of some of the limitations of Ria Services and how communication occurs with the client. From what I've found out the pagination information is xfered to the ria service via linq based operations. I'm not too up on Ria services at this level but I've found someone who has done some nice work to put together a library that exposes the pagination information via a custom DomainService. The library is available at: http://riatodal.codeplex.com/

Info on who and how to use the library: ryanmwright.com/tag/ria-services

This library is meant for something more general but focuses on the pagination restrictions with the supplied Ria DomainServices from MS.

Peter

0
votes

Well, it looks like you have done something confusing. I think you have doubled up on your paging logic and you are manually paging on the server and you have the Domain Datasource Control paging on the client.

You have set the LoadSize attribute to 20. This tells RIA Services that you want to page through the data in blocks of 20 records at a time. So, if the underlying domain operation ddsScheduleTemplates returns 50 records, you will get three pages and the Domain Datasource Control will automatically append .Take(20) and a .Skip(##) to filter down the result set to only one page at a time.

However, it also appears that you have added parameters to your domain operation to support paging because you have parameters for Page and PageSize. I assume that if you pass in Page=2 and PageSize=20 that you are appending a .Skip(40) and a .Take(20) in your Linq query on the server. If this is the case, then the Domain Datasource Control will think that there are only 20 records because that is the most your operation will return. So, there would be only one page.

If that doesn't help, then post the code for your server-side domain operation and I will see if I can route out the problem for you.

0
votes

What was being done was related to the issue I was trying to resolve. As I mentioned I am using a custom DomainService because I was required to work with a legacy DAL. I could not figure out how to get things to work with respect to pagination - one suggestion I had read was to supply custom paging params as query params. This did not work too well - actually not at all - may be because of the missing PageSize - but thought that this may not be required if doing custom paging.

With all that said as I mentioned in my previous comment (after research) I had found a nice library that allows the incorporation of legacy DALS into a DomainService and provides the logic as found in the MS RIA supplied Entity Framework domain services. That solved my problem.

0
votes

I have the same issue that you. What is happen if you go directly to page X ? Datapager returns to page 1 ? For me, if I go directly to some page , everything is Ok, but if I click on next or previous its goes to page 1.