为了简单起见,“部分”对象包含以下属性:LINQ,以确定是否孩子存在
SectionId
ParentSectionId
Name
目前,我有以下LINQ代码来获得给定段的孩子段:
List<Section> sections = SectionCache.GetAllSections();
sections.AsQueryable().Where(s => s.ParentSectionId == 10);
这给了我的部分的所有孩子的SectionId 10(再次,为了简单),但我需要进一步发展,只包括自己有孩子的部分。在SQL中,我可能会做这样的事情:
SELECT Section.SectionId,
Section.ParentSectionId,
Section.Name
FROM Section
INNER JOIN Section children ON children.ParentSectionId = Section.SectionId
WHERE Section.ParentSectionId = 10
GROUP BY Section.SectionId,
Section.ParentSectionId,
Section.Name
HAVING COUNT(children.SectionId) > 0
我怎样才能做到这一点的LINQ /什么是LINQ实现这一目标的最佳方式是什么?
谢谢
无需调用AsQueryable。那什么都不做。 – 2010-06-18 17:37:57