Friday, 16 October 2015

Paging a collection with LINQ

Question:
How do you page through a collection in LINQ given that you have a startIndex and a count?

Answer:
A few months back I wrote a blog post about Fluent Interfaces and LINQ which used an Extension Method on IQueryable<T> and another class to provide the following natural way of paginating a LINQ collection.
var query = from i in ideas
            select i;
var pagedCollection = query.InPagesOf(10);
var pageOfIdeas = pagedCollection.Page(2);

No comments:

Post a Comment