Using TypedList aggregate fields

Posts   
 
    
Posts: 28
Joined: 27-Mar-2007
# Posted on: 10-Mar-2008 12:57:51   

Hi, I am a little unclear as to the use of aggregate functions in the designer TypedList screens and how to access them from a databinding point of view. I have a Account entity with a 1:n relationship with User entity i.e. an account can have many users. I would like to display the number of users per account. I added both the Account and User entity to the AccountUsers typedList and marked the User.ID as a count aggregate. However, the examples shown in the manual show the use of GroupByCollections in this context. How is something like the following implemented as a typedlist and subsequently bound to a data control such as a gridview?

select Account.account_id, Account.account_name, Users, Account.create_date
from Account
inner join ( select AccUser.account_id, Count(AccUser.accuser_id) as Users
from AccUser            
group by AccUser.account_id) AccountUsers
on Account.account_id = AccountUsers.account_id 

Cheers

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 11-Mar-2008 01:55:20   

Hi,

You should:

  1. Design your _TypedList _so it have all the needed fields.
  2. At your code, apply and aggregate function (_count in this case) to the field you want (_accuser_id in this case).
  3. At your code, send a _GroupByCollection _object to the _FetchTypedList _call, containing all the fields but the aggregate one.
David Elizondo | LLBLGen Support Team
Posts: 28
Joined: 27-Mar-2007
# Posted on: 13-Mar-2008 10:35:20   

Thanks for the information.

I'd seen something like this in the 2.5 manual page 212. I had hoped that there was a way to use the aggregate column in the design of TypedLists to generate a derived column and access this column in code when binding to a datacontrol. At the moment I use a stored procedure which turns into a TypedView object.

Mdmasonmbcs