For simplicity, a "Section" object contains the following properties:
SectionId
ParentSectionId
Name
I currently have the following LINQ code to obtain child sections of a given section:
List<Section> sections = SectionCache.GetAllSections();
sections.AsQueryable().Where(s => s.ParentSectionId == 10);
This gives me all children of the section with a SectionId of 10 (again, for simplicity), but I need to develop this further to only include sections that themselves have children. In SQL, I might do something like this:
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
How can I achieve this in LINQ/what is the best way to achieve this with LINQ?
Thanks