0

I want to implement pagination using PagedList but the issue is that when I use entity framework, I have to get the whole list for the model and then pass it to the PagedList extension. For large data sets this will take more time.

    var result = db.company.ToList().ToPagedList(page?? 1,10);

I want to filter the list of results to the data set that will be displayed and then pass it to PagedList.

Is there any solution for this or some other way to do this type of pagination?

RickL
  • 3,318
  • 10
  • 38
  • 39
  • 2
    You do not need to _get whole list of model_ (and should not be). Remove the `.ToList()`. The `.ToPagedList()` method uses `.Skip()` and `Take()` to build a SQL query that returns only the 10 records you need. And if you want to filter the data, use a `.Where()` clause –  Oct 09 '17 at 21:20
  • I want to see query generated by this, how to see this ? – Umar Farooq Nasir Oct 09 '17 at 21:57
  • [How do I view the SQL generated by the Entity Framework?](https://stackoverflow.com/questions/1412863/how-do-i-view-the-sql-generated-by-the-entity-framework) –  Oct 09 '17 at 22:00
  • I tried this already but this is not successful – Umar Farooq Nasir Oct 09 '17 at 22:01

0 Answers0