Get the total number of records when doing pagination

前端 未结 2 394
别那么骄傲
别那么骄傲 2020-12-17 16:29

To get a page from a database I have to execute something like this:

var cs = ( from x in base.EntityDataContext.Corporates
   select x ).Skip( 10 ).Take( 10         


        
2条回答
  •  难免孤独
    2020-12-17 16:39

    Bottom line: you have to run two queries. You simply can't get around it.

    Here's a good way to do it, however, that caches the original LINQ query and filter, making for less copy/paste errors:

    var qry = from x in base.EntityDataContext.Coporates select x;
    var count = qry.Count();
    var items = qry.Skip(10).Take(10).ToList();
    

提交回复
热议问题