I have the following objects:
public class Agency
{
public int ID;
public IEnumerable<BusinessUnit> BusinessUnits;
}
public class BusinessUnit
{
public int ID;
public decimal AmountSpent;
public IEnumerable<Client> Clients;
}
public class Client
{
public int ID;
public decimal AmountSpent;
}
Now, I have a IEnumerable<Agency
> which contains several agencies, these agencies contain several BusinessUnits, and those BusinessUnits contain several clients.
It might look something like:
Agency1
++BusinessUnit1 - $20
++++Client1 - $10
++++Client2 - $10Agency2
++BusinessUnit2 - $20
++++Client1 - $20Agency3
++BusinessUnit1 - $10
++++Client5 - $5
++++Client6 - $5
++BusinessUnit2 - $25
++++Client1 - $25
Now, what I'm looking to do, is create a list of BusinessUnits and Clients, but for all agencies, without duplicates.
So, I'm looking to turn that list of Agencies into:
All Agencies
++BusinessUnit1 - $30
++++Client1 - $10
++++Client2 - $10
++++Client5 - $5
++++Client6 - $5++BusinessUnit2 - $45
++++Client1 - $20
++++Client1 - $25
Where I simply have a list of unique BusinessUnits (with their correct AmountSpent total across all instances of that particular BusinessUnit), and with a list of unique clients under them, with the correct AmountSpent total for each instances of that particular client under that business unit.
Is it possible with LINQ that I can I query my IEnumerable<Agency
> Agencies list to return my distinct list of BusinessUnit/Client combinations with the correct sums?