Hey all, i'm trying to achieve the following query with LINQ (or using predicates for that matter but i figured linq would be easier)
SELECT CategoryID, Description,
(SELECT COUNT(*) FROM Projects WHERE Project.ProjectID IN
(SELECT ProjectID FROM ProjectGroup WHERE ProjectGroup.ProjectID IN
(SELECT ProjectID FROM ProjectGroupCategories WHERE ProjectGroupCategories.CategoryID = Category.CategoryID)
)
) AS ProjectCount
FROM Category
I have the following tables
ProjectGroup
Projects
ProjectGroupCategories
Category
I want to get a list of categories and the number of Projects associated with the ProjectGroup which is associated to the category through the m-n lookup ProjectGroupCategories.
It would be nice to also see how to exclude all categories which do not have any projects.
Any help is greatly appreciated. Thanks.