Is there a paging solution for ASP.NET MVC that does paging in the database?

前端 未结 4 1809
小蘑菇
小蘑菇 2021-02-02 17:35

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

4条回答
  •  天命终不由人
    2021-02-02 18:09

    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.

提交回复
热议问题