I am using the Entity Framework. I have a many to many relationship Articles <-> Categories. Each article can belong to many categories, and each category can belong to more than one article. I can get the COUNT of articles within each category:
public IEnumerable<MenuCategory> GetMenuCategories()
{
return (from c in db.CategorySet.Include("Articles")
orderby c.CategoryName
select new MenuCategory
{
CategoryID = c.CategoryID,
CategoryName = c.CategoryName,
CountOfCategory = c.Articles.Count()
});
}
But I also need to get the total number of articles so that I can calculate what percentage of articles is in each category. Can anyone tell me how to do that by extending the code above and without making a separate call to the database?
Thanks