1
votes

Ok so I am just trying to learn some of this fun stuff now, and was wondering if I could get some feedback?

Tables Categories Postings Postings_Categories(Join Table)

I need to figure out how to recurse through all of the categories and get the number of postings in each category. As well, if it can all be done with one query, I need to list the subcategories of each parent category.

Categories table has CategoryID, CategoryName, CategoryDescription, ParentCategoryID

1

1 Answers

0
votes

It would be nice if you wrote approach you used (DB first/Code First/POCOs). If DB first then easy:

context.Categories.Include('Subcategories').ToList();//list of categories and their subcategories

context.Categories.Select(c => new { Category = c, Postings = c.Postings.Count() }).ToList();//categories and number of postings

Of course your database needs to be set correctly, you have to create foreign keys, association table should have only ids of both tables. If database is not declared correctly, creating these queries could be problematic.