【发布时间】:2011-01-13 11:34:28
【问题描述】:
我有一个具有树结构 (Id,MasterId) 的类别表 我想选择属于某个类别和所有子类别的所有产品。
今天我使用了这个有效的 SQL 查询,但我想添加分页,使用纯 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;
任何想法如何通过分页(当前页面、每页产品数、总产品数)获得一个不错的 LINQ 查询?
【问题讨论】:
标签: c# linq entity-framework