How can I use Aggregate function in Typedview?

Posts   
 
    
sbalaji123
User
Posts: 26
Joined: 13-Oct-2006
# Posted on: 27-Dec-2006 12:19:20   

Hi,

I have created dal.dll using LLBLGenpro version 2.0 in my web application and referring it.

My platform is C#.net 2.0,SQL Server 2005,SQL Server reporting service2005,dundas,telerik etc.,

How can I use Aggregate function in Typedview?

Please anyone suggest to me that how to achieve this.

Thanks in advance, Balaji

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 27-Dec-2006 14:40:59   

Assuming you are using the Adapter model:

Use the FetchTypedView() overload which accepts a GroupByCollection. And set the AggregateFunctionToApply attribute to the fields that you want to be aggregated in the supplied TypedView fields.

Refer to the following LLBLGen Pro docs examples for hints on how to do that: "Using the generated code -> Adapter -> Using GROUP BY and HAVING clauses" "Using the generated code -> Field expressions and aggregates"

sbalaji123
User
Posts: 26
Joined: 13-Oct-2006
# Posted on: 27-Dec-2006 15:02:46   

Hi, Sorry we are using Selfservicing method...

Need your help as soon as possible.

Thanks in advance, Balaji

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 27-Dec-2006 15:15:28   

Just use the corresponding sections from the docs. Read the following instead "Using the generated code -> SelfServicing -> Using GROUP BY and HAVING clauses"

And you should use the GetFields method of the typedView to return a list of fields where you can pick one or more fields and set their aggregateFunction as follows:

IEntityFields fields = yourTypedView.GetFields();
fields[0].AggregateFunctionToApply = AggregateFunction.CountDistinct;
sbalaji123
User
Posts: 26
Joined: 13-Oct-2006
# Posted on: 28-Dec-2006 11:47:09   

Hi, Thanks for your immediate response.

But my requirement is somewhat different like below:

I have one typedview called "testview" like "SELECT fld1,fld2,fld3,fld4,fld5,fld6,fld7,fld8,fld9,fld10 from <table>".

From this typedview, i need the values of max(fld1),min(fld1),max(fld2),min(fld2).

I need to achieve one more thing i.e., the selection of fields will be dynamic from the typedview. For example sometimes it may be like max(fld1),min(fld1),max(fld3),min(fld3).

Is it possible to achieve this in LLBLGEN (DAL.dll) If "yes" means how can i achieve this from typedview "testview"?

Thanks in advance, Balaji

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 28-Dec-2006 14:00:04   

So you would dynamically set the AggregateFunctionToApply to the selected fields.


fields[x].AggregateFunctionToApply = AggregateFunction.Max;
fields[y].AggregateFunctionToApply = AggregateFunction.Min;
...

If you want to get 2 or more aggregate values (Max & Min) for the same field. Then you might want to use a dynamicList where you define fields yourself and assign the aggregateFunctions to them. This will enable you to define a field more than once. applying a different aggregate function to each definition. Please refer to the LLBLGen Pro docs "Using the generated code -> SelfServicing -> Using dynamic lists"

Or you might want to select each value alone in one scalar query. Please refer to the LLBLGen Pro docs "Using the generated code -> Field expressions and aggregates"