Generate Tag Cloud using Entity Framework

  • Thread starter Thread starter Phil
  • Start date Start date
P

Phil

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 total number 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?

Thanks
 
Do you need it to be in the same query, or can you do one separate query to
retrieve that. If so, I would just use db.ArticleSet.Count(). Am I missing
something?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top