Paging with PagedList, is it efficient?

后端 未结 7 1460
执念已碎
执念已碎 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<Client>. This will indeed bring all the clients into memory and then page through that. Instead, you should look for methods that use IQueryable<T>, specifically Skip and Take, so paging should look like

    IQueryable<Client> clients = repo.GetClients();          // lazy load - does nothing
    List<Client> 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

    0 讨论(0)
提交回复
热议问题