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);
You can get the code from the MSDN Code Gallery Page: Pipelines, Filters, Fluent API and LINQ to SQL.
< br > via < a class="StackLink" href=" http://stackoverflow.com/questions/66/" >Paging a collection with LINQ< /a>
0 comments:
Post a Comment