ASP.NET with WCF Services - how to page data

I have a WCF service with functions that return lists, such as one to return a list of customers

[OperationContract]
IList<Customer> GetCustomers();

My ASP.NET page may do:

var top10Customers = Model.GetCustomers().Take(10);
var first10Customers = Model.OrderBy(c => c.ID).Take(10);

It is my understanding that the following code woulld return all Customers from the WCF service and THEN apply OrderBy and Take(10)

It seems inefficient to return the entire data set in one go, especially as the WCF service may reside on a different machine to the ASP.NET website. In which case how best can I page the results set or allow LINQ operations on it?

The only option I can see at the minute is to add paging options to the function, but this seems inefficient to re-write this code all the time:

[OperationContract]
IList<Customer> GetCustomers(int from, int numResults);

Answers


I'd suggest adding the parameters to the GetCustomers method and then execute the LINQ on that side in order to generate the most efficient SQL?

[OperationContract] 
IList<Customer> GetCustomers(int fromRecoard, string orderBy); 

The order by will be a little trick, since you'll need to convert from a sting into a lamda expression and use the property of Customer, but there are plenty of samples on the web.

For more info on IQueryable in .Net 4.5 have a look at this blog post under the OData section.

http://www.davidhayden.me/blog/asp.net-mvc-4-web-api-routes-and-apicontroller


Need Your Help

Memory leak in code snippet

c++ memory-leaks

I'm trying to dust off my C++. I knocked together a simple program to find the Fibonacci sequence with memoization. There's a memory leak, and I can't seem to figure out why. The leak is reported...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.