Best practice?: Only Count of SubCollections needed

Posts   
 
    
G.I.
User
Posts: 172
Joined: 09-Jun-2005
# Posted on: 04-Jul-2007 14:48:41   

Hi,

I have a Project, and that project can have sub projects and linked External Projects. On a page where I show some details of a project, I just need to show how many subprojects and linked external project a project has.

So for example:

Project 1: Description: blabla Status: Open Sub Projects: 8 External Projects: 4

and more information ...

I don't need the rest of the info on this page ... what is the best way to get this information?

I don't really need to edit data here on this page, so I can use a dynamic list, but there is quite some other data I need to show (also related) and it's much more clear in code to use the entities and relations.

I can also just retrieve all the data anyway ... it's almost never above 10 for each related project type and just do a count on the collection on projectentity

I can also use 2 getscalar functions to retrieve these values.

What is the best way to solve this issue? Is there another effective way?

Best regards,

  • G.I.
Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 04-Jul-2007 15:38:37   

What is the best way to solve this issue? Is there another effective way?

There are many ways to perform this. If you need the data for a ReadOnly purposes, it sounds better to use a DynamicList. And you can use a ScalarQueryExpression as follows:

// C#
ResultsetFields fields = new ResultsetFields(2);
fields.DefineField(OrderFields.CustomerID, 0);
fields.DefineField(new EntityField2("NumberOfOrders", 
    new ScalarQueryExpression(OrderFields.OrderId.SetAggregateFunction(AggregateFunction.Count),
                (CustomerFields.CustomerId == OrderFields.CustomerId))), 2);
DataTable results = new DataTable();
DataAccessAdapter adapter = new DataAccessAdapter();
adapter.FetchTypedList(fields, results, null);