【发布时间】:2014-04-02 03:20:44
【问题描述】:
我在使用“LINQ to entity”显示每个产品并在 ASP.NET MVC 中实现分页时遇到此错误。:
The method 'Skip' is only supported for sorted input in LINQ to Entities.
The method 'OrderBy' must be called before the method 'Skip'."
LINQ:
Model.Name = db.Products.Where(p => p.ProductSubcategoryID == id)
.Skip((page - 1) * pageSize)
.Take(pageSize)
.ToList();
我该如何解决?如果我输入 OrderBy 而不是 Where 会发生什么?
【问题讨论】:
-
您是否尝试使用
OrderBy而不是Where?当你这样做时发生了什么? -
@Cupcake 是的,我试过了。
OrderBy的结果返回所有与特定 ID 无关的产品。
标签: c# linq entity-framework linq-to-entities