10031103
10031103

Reputation: 93

Paging with the Entity Framework in an ASP.NET MVC Application

Considering the code below, using EF and PagedList:

var students = from s in db.Students
                  select s;

int pageSize = 30;
int pageNumber = (page ?? 1);
return View(students.ToPagedList(pageNumber, pageSize));

If the Students table has 10,000 records, but I only want to display 30 records(one page), does the code above return all of the 10,000 records from DB then pass to view?

If it is, is it better to have a Stored Procedure in DB and let the Stored Procedure doing the pagination and only return 30 records from DB, is this the better way for the performance(only transfer 30 records over network)?

Upvotes: 1

Views: 1987

Answers (1)

OdeToCode
OdeToCode

Reputation: 4986

This is Troy Goode's Paged List (https://github.com/TroyGoode/PagedList)?

The paging happens inside of SQL Server as long as the data source is IQueryable, which looks like it should be in your code example.

Upvotes: 2

Related Questions