C# Entity Framework Pagination

前端 未结 5 1306
陌清茗
陌清茗 2020-12-09 04:33

Is there a way to get the row count of a complex Linq query and millions of records without hitting the db twice or writing 2 separate queries??

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-09 05:24

    If you need a quick solution you can use XPagedList https://github.com/dncuug/X.PagedList. XPagedList is a library that enables you to easily take an IEnumerable/IQueryable, chop it up into "pages", and grab a specific "page" by an index. For example

    var products = await _context.Products.ToPagedListAsync(pageNumber, pageSize)
    

提交回复
热议问题