GroupBy and Entities/Collections

Posts   
 
    
Posts: 5
Joined: 07-Aug-2006
# Posted on: 07-Aug-2006 16:15:15   

I've generated a bunch of Entity/Collection classes which I am happily using, but now I've been asked to perform some grouping on the results.

I've been happily creating PredicateExpressions, RelationCollections and SortExpressions, but I'm at a loss on how to include a Group By.

I've created a GroupByCollection and added the IEntityField that I would like to group by, but don't know how to then include this so that when I call GetMulti on my Collection class the grouping is performed.

Is it even possible?

Apologies if this is a bit of a newbie question, but all information I've been able to find points to using TypedLists and such like.

Thanks,

CD

Jessynoo avatar
Jessynoo
Support Team
Posts: 296
Joined: 19-Aug-2004
# Posted on: 07-Aug-2006 17:23:26   

You cannot use group by nor agregates on entities and collection because entities stand for entity records, which you can fetch, save, delete... while group by and aggregates involve merging the data, which is not consistent with the nature of the data entities can hold.

So when looking for groupby clauses, you should turn to typedlists.

One thing that you can do with entities though is applying expressions to the fields in accordance with their type. Then, with a combination of predicates you might be able to get specially carved data, but keep in mind that entities are real objects in the first place, and typedlists dynamic custom views.

psandler
User
Posts: 540
Joined: 22-Feb-2005
# Posted on: 07-Aug-2006 17:44:23   

Another option that we use quite frequently is to apply the aggregate in a view, then create a custom relation between that view and the entity in question, and include the view entity in the prefetch path.

You could, of course, simply use a view to begin with, and just map your entity to the view directly. I find this method to be more of a maintanence headache, though.