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).
// 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);
blog comments powered by Disqus