Paging with PagedList, is it efficient?

后端 未结 7 1458
执念已碎
执念已碎 2020-12-25 14:14

I have been trying to implement paging for quite a while now and I found this tutorial for paging with MVC: ASP.NET MVC Paging Done Perfectly

Now, in this solution,

7条回答
  •  春和景丽
    2020-12-25 15:10

    The linked tutorial looks odd, because it uses a List. This will indeed bring all the clients into memory and then page through that. Instead, you should look for methods that use IQueryable, specifically Skip and Take, so paging should look like

    IQueryable clients = repo.GetClients();          // lazy load - does nothing
    List paged = clients.Skip(20).Take(10).ToList(); // execute final SQL
    

    Depending on what mappers you use, you will find similar methods in EF, NHibernate, Linq-to-SQL etc

提交回复
热议问题