Paging in Entity Framework

前端 未结 6 1238
情书的邮戳
情书的邮戳 2020-12-03 00:56

In Entity Framework, using LINQ to Entities, database paging is usually done in following manner:

int totalRecords = EntityContext.Context.UserSet.Count;
var         


        
6条回答
  •  自闭症患者
    2020-12-03 01:30

    This queries are too small for DBManager and I can not understand why you want to do this, anyway for reduce it to ONE database call use this:

    var list     = EntityContext.Context.UserSet
                     .Skip(startingRecordNumber)
                     .Take(pageSize)
                     .ToList();
    int totalRecords = list.Count;
    

提交回复
热议问题