How to get data in chunks from a WCF Service

This is a simple solution on how to get data in chunks from a WCF service (e.g. a paged list of results)

Assuming that your service pulls data from a SQL Server database, you can use Linq2Sql and create your data context, OR if you are not using SQL Server, then the Microsoft Entity Framework may suit you.

Here is the code:

public IList <customers> GetCustomers(int pageIndex, int pageSize, out int total)
 {
  using (var db = new NorthwindDataContext())
    {
     var customers = db.Customers;
     total = customers.Count();
     var results = customers
      .Skip(pageIndex * pageSize)
      .Take(pageSize);
     return results.ToList();
    }
 }


This entry was posted on Friday, June 12th, 2009 at 11:09 pm and is filed under Programming. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply

Your comment