I've dealt with some simple LINQ queries before, but am not sure how to tackle this one...
I've got a project I'm working on where I'm dealing with two classes I've created, 'Package' and 'Product' (along with other classes).
I've also created a Job class which houses a List<Package> and inside the Package class it houses a List<Product>.
(NOTE): a Package is just a grouping of Products. so each Package could have 2 different scenarios: 1)it has all unique Products or 2) it could have some of the same Products that other Packages have and some unique)
Expand|Select|Wrap|Line Numbers
- //This is just an abstract view of the classes
- // there are other things in each class
- public class Job
- {
- int jobID;
- List<Package> packages;
- }
- public class Package
- {
- int packageID;
- List<Product> products;
- }
- public class Product
- {
- int productID;
- int quantity;
- }
So now for my question, as I explained in the above note, some Packages can have the same Product in them. Well I'm looking to write a function in the Job class to pull a LINQ query to return each unique Product class, AND also the sum of the 'quantity' data member in the Product class.
This analogy may help: if a grocery store wanted to take every purchase (package class) from a single day (job class) and wanted to know the total quantity of each product sold and the name of the product.
the ideal query would return:
(ID#1:Qty 4),(ID#2:Qty 1),(ID#3:Qty 2),(ID#12:Qty 3),(ID#13:Qty 1)
If I did a horrible job of explaining or if you need more info, just let me know and I'll find another way of explaining it!
Thank you!