RIA Services Nuggets – DataPager Issues

Friday I was really brave. (or just crazy) I decided to use Entity Framework as a data source (for the first time) and tried to show the datapaging feature with .NET RIA Services. (Rule No.1: Don’t ever try a demo you’ve never tried before. :)) It has such a cool lazy loading feature. My xaml looked like this:


Then it hit me in the face. 20 items were loaded just fine but from 20 to I don’t know how many it just wouldn’t work. The data never arrived. I was quite surprised. Finally I decided to give it up since it’s probably a bug and RIA is just CTP. Then I came home and tried to reproduce the issue and I succeeded! 🙂 I had to face the fact: IT WAS NOT WORKING! Come ooooon! Such a basic thing and it’s bugy…. It made me really upset. 🙂

Then I got into it a little deeper and tried to debug the issue. I found an interesting error message:

“The method ‘Skip’ is only supported for sorted input in LINQ to Entities. The method ‘OrderBy’ must be called before the method ‘Skip’.”

Well yeah… that was it. The paging functionality is implemented with the use of Take and Skip methods. However in Entity Framework you can call these methods only on sorted collections and by deafult ObjectQueries are not sorted unless you call OrderBy() on them. So I had to modify the GetCustomer operation in my DomainService like this:


Now it’s working just fine. (SortDescriptors defined on the DomainDataSource would have been just fine as well)

But why isn’t this documented anywhere? Or did I missed something?


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s