Soldato
- Joined
- 27 Mar 2003
- Posts
- 2,710
Ok you could try something like this then:
This is untested by the way
So we do the grouping first on your category name and then total up the number of projects afterwards.
I haven't used the GroupBy in LINQ too much and if I do it is usually to get something simple. Like a list of strings etc.
Hope this helps. (I'm still picking up LINQ myself)
This is untested by the way
Code:
db.SubCategories.GroupBy(subcategory => subcategory.Category.Description).
Select(groupedCategory => new
{
CategoryDescription = groupedCategory.Key
, TotalNumberOfProjects = groupedCategory.Sum(subcategory.ProjectCategories.Any() ? subcategory.ProjectCategories.Count() : 0)
}
).ToList()
So we do the grouping first on your category name and then total up the number of projects afterwards.
I haven't used the GroupBy in LINQ too much and if I do it is usually to get something simple. Like a list of strings etc.
Hope this helps. (I'm still picking up LINQ myself)