私のデモでは、データベースに TProduct、TCategory、TProductCategoryMap の 3 つのテーブルがあります。
TProduct (ProductId int PK、OtherFields)
TCategory (CategoryId int PK、OtherFields)
TMap (ProductId int PK、CategoryId int PK)
ここで、特定のカテゴリ ID を持つ製品の 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;
ここで製品を返品すれば、すべて問題ありません。しかし、次のような pagedlist を返すと:
return new PagedList<TProduct>(products, pageIndex, pageSize);
生成された SQL テキストにより、「ランキング関数 "ROW_NUMBER" には ORDER BY 句が必要です。」という構文エラーが発生します。
間違った linq 式を使用していませんか? では、正しい結果を得るにはどうすればよいでしょうか。
アドバイスをください、ありがとう。