Aggregate sum

Posts   
 
    
Posts: 13
Joined: 07-Jun-2005
# Posted on: 08-Feb-2006 05:03:39   

I know this must be dead simple but could someone please put a sample piece of code that does this (in c#):


select sum(englishQuantity), sum(frenchQuantity)
from LineItem
where productid = 12

I've been looking around and haven't found something I could re-use (it's probably right in front of me but I can't see itflushed ).

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 08-Feb-2006 07:57:52   
Posts: 13
Joined: 07-Jun-2005
# Posted on: 08-Feb-2006 20:40:16   

Walaa wrote:

Would this thread be helpful? http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=2560

Yes - that is what I am doing now (using similar code). What I was hoping to fill an entity with more than one aggregate result but I guess that doesn't make sense - which entity would I use to store the results rage .

Thanks for the response.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 09-Feb-2006 07:10:30   

Why do you want to store the results in an Entity?

Anyway you can do this if created a database view that holds your Query, then you may use the LLBLGen Pro Designer to map this view to an Entity.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39930
Joined: 17-Aug-2003
# Posted on: 09-Feb-2006 09:15:30   

chris_vickerson wrote:

I know this must be dead simple but could someone please put a sample piece of code that does this (in c#):


select sum(englishQuantity), sum(frenchQuantity)
from LineItem
where productid = 12

I've been looking around and haven't found something I could re-use (it's probably right in front of me but I can't see itflushed ).

You can also use a dynamic list for this, based on LineItem entity fields. ResultsetFields fields = new ResultsetFields(2); fields.DefineField(LineItemFieldIndex.EnglishQuantity, 0, "EnglishQuantity"); fields.DefineField(LineItemFieldIndex.FrenchQuantity, 1, "FrenchQuantity"); fields[0].AggregateFunctionToApply = AggregateFunction.Sum; fields[1].AggregateFunctionToApply = AggregateFunction.Sum;

and then you use the dynamic list fetch logic for the template group you're using (so either adapter or selfservicing). See the documentation about details on dynamic lists.

Frans Bouma | Lead developer LLBLGen Pro