Can we control LINQ expression order with Skip(), Take() and OrderBy()

后端 未结 6 770
日久生厌
日久生厌 2021-02-08 14:16

I\'m using LINQ to Entities to display paged results. But I\'m having issues with the combination of Skip(), Take() and OrderBy() calls.

6条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-08 15:06

    One way:

    var query = ctx.EntitySet.Where(/* filter */).OrderBy(/* expression */).ToList();
    int total = query.Count;
    var result = query.Skip(n).Take(x).ToList();
    

    Convert it to a List before skipping. It's not too efficient, mind you...

提交回复
热议问题