To dive right in, here's a simplified version of my database:
In my UI, I want to display each Category along with the number of items linked to it.
The user can then click on the category and see that total broken down by each Sub Category.
My question is, how do I get this data using LINQ?
In plain SQL, I'd do something like:
How would I do something similar in LINQ? I'm assuming that the advantage of LINQ would be that it's object based, so I could have a count of an ItemCategory object, and then link back through each Category in my UI?
This is in C#.Net by the way (MVC5)
Sorry if I've explained this really badly!
Code:
Category
- ID
- CategoryName
SubCategory
- ID
- SubCategoryName
- ParentCategoryID
Item
- ID
- ItemName
ItemCategory
- ID
- ItemID
- SubCategoryID
In my UI, I want to display each Category along with the number of items linked to it.
The user can then click on the category and see that total broken down by each Sub Category.
My question is, how do I get this data using LINQ?
In plain SQL, I'd do something like:
Code:
SELECT CategoryName
, SubCategoryName
, COUNT(ItemID)
FROM Table
GROUP BY CategoryName
, SubCategoryName
How would I do something similar in LINQ? I'm assuming that the advantage of LINQ would be that it's object based, so I could have a count of an ItemCategory object, and then link back through each Category in my UI?
This is in C#.Net by the way (MVC5)
Sorry if I've explained this really badly!
