Get the total number of records when doing pagination

前端 未结 2 384
别那么骄傲
别那么骄傲 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:47

    To get the total number of records before skip/take you have to run a separate query. Getting the actual number returned would use Count(), but wouldn't result in another query if the original query was materialized.

    var q = from x in base.EntityDataContext.Corporates 
            select x;
    
    var total = q.Count();
    var cs = q.Skip(10).Take(10);
    var numberOnSelectedPage = cs.Count();
    

提交回复
热议问题