databasepaginationlinq-to-sql

Is there a paging solution that does paging in the database?


Most of the ASP.NET MVC paging solutions I have found by googling look like they get all rows from a database table in the form of a IEnumerable collection, perform some paging conversion on the IEnumerable collection, and then return the results to the view. I want to be able to page on the DB side but still have some paging class to do the page number calculations and HTML generation. Is there a solution out there that does this? Or are the ones i've been looking at do this, but i'm not seeing it because i'm looking at them wrong?

here's what i've been looking at:


Solution

  • Look at the Gu's Nerdinner sample.

    var upcomingDinners = dinnerRepository.FindUpcomingDinners();  
    var paginatedDinners = upcomingDinners.Skip(10).Take(20).ToList(); 
    

    Even though FindUpcomingDinners() gets all the upcoming dinners, the query isn't executed at the database until you call ToList() in the next line. And that is after you Skip 10 rows and only get
    the next 20.