Snippet Fire

Beta
 Log In    |   Sign Up

.NET : Paging Using Entity Framework

Added on Dec-14-2011 by admin
For .NET

Tags : c#entity frameworklinqpaging

To use paging when querying Entity Framework simply use the LINQ Take and Skip extension methods. The Take extension method will 'take' a set number of records (this is in effect the page size). The Skip extension skips to the required page (although you be required to pass Skip the number of records you wish to skip over).

DOWNLOAD

// db is an instance of an object which inherits from DbContext. 
// Snippets is a DbSet

var pagedList = db.Snippets
                            .Where(x => x.ID == 3)
                            .Skip((pageNumber - 1) * pageSize)
                            .Take(pageSize);

    

Report Snippet

blog comments powered by Disqus