To implement paging logic, we can update our Index action method so that it applies additional Skip
and Take operators to the returned IQueryable<Dinner> sequence before calling ToList on it:
//
// GET: /Dinners/
public ActionResult Index() {
var upcomingDinners = dinnerRepository.FindUpcomingDinners();
var paginatedDinners = upcomingDinners.OrderBy(d => d.EventDate)
.Skip(10)
.Take(20).ToList();
return View(paginatedDinners);
}
Code snippet 1-64.txt
The preceding code skips over the first 10 upcoming Dinners in the database and then returns 20
Dinners. Entity Framework is smart enough to construct an optimized SQL query that performs this
skipping logic in the SQL database — and not in the web server. This means that even if we have
millions of upcoming Dinners in the database, only the 10 we want will be retrieved as part of this
request (making it efficient and scalable).
from:professional asp.net mvc 2