ツリー構造(Id、MasterId)を持つカテゴリテーブルがあります カテゴリとすべての子カテゴリに属するすべての製品を選択したいと考えています。Entity Frameworkのカテゴリツリーを選択してください
今日私は動作するこのSQLクエリを使用しますが、ページネーションを追加したいのですが、それは純粋なLINQクエリで簡単になります。私は、Entity Frameworkは、ページネーションでこれに素敵なLINQクエリを取得する方法任意のアイデア(現在のページ、ページあたりの製品数、総生産数)4.
@Count int = 100,
@CategoryId int
with mq as
(
select c.Id as parent, c.Id as child
from dbo.Categories c
where c.Id = @CategoryId
union all
select q.child, c.Id
from mq q
inner join dbo.Categories c on q.child = c.MasterId
)
select top (@Count) P.* from Products P
inner join ProductToCategory PC ON(PC.ProductId = P.Id)
where PC.CategoryId in (
select child from mq
)
and P.PublishStatus = 1
order by P.PublishedDate DESC;
でしょうか?
式でこれを達成する方法はありますか? [this](http://stackoverflow.com/a/15636530/75500)のようなもの? – Shimmy