getting aggregates from collection

Posts   
 
    
morten71
User
Posts: 80
Joined: 13-Jan-2009
# Posted on: 07-Sep-2009 15:59:34   

I have a Reports table with column a, b and c:

Example: Country, Product, Value US, GR1, 2 US, GR2, 2 US, GR3, 2 US, GR1, 2 US, GR3, 2 US, GR3, 2 UK, GR1, 2 UK, GR2, 2 UK, GR3, 2 UK, GR1, 2 UK, GR3, 2 UK, GR3, 2

I load the data into a ReportsCollection using the GetMulti function.

How do I get aggregates like: - SUM Value group by Country - SUM Value group by Country and Product - SUM Value group by Product

...without having to call the database again or create a stored procedure?

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 07-Sep-2009 16:23:24   

You could have these fetched from the database in the first place, using DynamicList instead of fetching the entityCollection.

But if you have to fetch the collection for any reason, and you want to get these aggregates without visiting the database again, you could just loop into the collection and programatically collect the data you need, and store them into a structure of your own. After all you need some dataStructure to hold your aggregate data.

For example to have the (SUM Value group by Country), you can use a dictionary, storing the Country as the dictionary key and summing the Values int the dictionary value.