Aggreate on in memory collection

Posts   
 
    
DannyGreen
User
Posts: 12
Joined: 25-Jul-2008
# Posted on: 24-Jul-2009 16:19:07   

I am using the Adapter, and wish to do a simple Sum Aggreate on an in memory Enitity Collection. I have searched the documentation and forum, and it seems like AggregateSetPredicate is what i should be using, but I cannot get it to work and am a little confused by it's usage. I do not need to qualify what rows to sum, I just wish to get the sum of a few of the fields contained in the collection. I am constrained to .NET 2.0, so I cannot use Linq.

Here is the line of code that I have:

IPredicate sumFilter = new AggregateSetPredicate("AwipTotalCostsToDate", AggregateSetFunction.Sum, FcsVwAcctWipNoBidFields.AwipId,  ComparisonOperator.GreaterEqual ,0, null);

I get the error that AwipTotalCostsToDate isn't found, though it is definately a field on the entity (when I tried to use the MemberNames like in the documentation, intellisense shows nothing, so again confused). Also, I don't really understand what the 'Value Producer' field is for, I just put the ID field in there becuase that seemed to be what was in the example. I also don't really need the 'Greater Than or Equal' operator, but seemed forced to include it.

Thanks! Danny

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 24-Jul-2009 19:57:50   

Hi Danny,

Not supported as far as I know. With .Net 3.5 would be easy using LinqToObjects and Lambda expressions. So, you will have to do a loop, or update to 3.5.

David Elizondo | LLBLGen Support Team
DannyGreen
User
Posts: 12
Joined: 25-Jul-2008
# Posted on: 24-Jul-2009 22:49:36   

Could you possible provide a quick snippet using Linq to Objects?

Thanks!

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 25-Jul-2009 08:02:40   
decimal theSum = (decimal) (from o in awipsInMemory 
     select o.AwipTotalCostsToDate).Sum();
David Elizondo | LLBLGen Support Team