在我的演示中,我在数据库中有三个表,TProduct、TCategory 和 TProductCategoryMap。
TProduct (ProductId int PK, OtherFields)
TCategory (CategoryId int PK, OtherFields)
TMap (ProductId int PK, CategoryId int PK)
现在,我需要获取具有特定 categoryid 的产品的 PagedList。
这是我的代码:
IQueryable<Product> products = from product in _repo.All<TProduct>()
join map in _repo.All<TMap>() on product.ProductId equals map.ProductId
where map.CategoryId == specificCagetoryId
select product;
如果我在这里停下来退回产品,一切都很好。但如果我返回这样的分页列表:
return new PagedList<TProduct>(products, pageIndex, pageSize);
生成的sql文本会导致语法错误“排名函数“ROW_NUMBER”必须有ORDER BY子句。”
我是否使用了错误的 linq 表达式?那我怎样才能得到正确的结果呢?
给我一些建议,谢谢。