Member Collections Sorting

Posts   
 
    
Samuel
User
Posts: 9
Joined: 04-Dec-2004
# Posted on: 04-Dec-2004 18:32:03   

I understand how to sort an entity collection, and how to sort the collection on a foreign field, but how do you sort a entity child collection on a field of that collection

IE Table Product Table Colors

Return ProductEntinty with Color collection sorted by field ColorDisplayOrder(in colors table)

I've been thu the docs and the forums to no avail. I'm new to the framework so maybe it's just something simple I'm missing confused .

Thanks

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 05-Dec-2004 12:03:10   

You can sort the data read from the database based on a field (or fields) in related entities, however not when the data is already in memory.

To sort the products fetched from the database based on the color name, you have to specify a relationcollection with the relation and a sortclause on color.name:


IRelationCollection relations = new RelationCollection();
relations.Add(ProductEntity.Relations.ColorEntityUsingColorId);
ISortExpression sorter = new SortExpression(SortClauseFactory.Create(ColorFieldIndex.Name, SortOperator.Ascending));
ProductCollection products = new ProductCollection();
products.GetMulti(null, 0, sorter, relations);

This will fetch all products, sorted on color.name.

Frans Bouma | Lead developer LLBLGen Pro
Samuel
User
Posts: 9
Joined: 04-Dec-2004
# Posted on: 05-Dec-2004 22:20:41   

I appreciate your response, however what I want is for a product entity to be returned with it's color collection presorted by a color display order value in the colors table. I'm not concerned with the order of the products.

Thanks

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 06-Dec-2004 10:00:17   

Samuel wrote:

I appreciate your response, however what I want is for a product entity to be returned with it's color collection presorted by a color display order value in the colors table. I'm not concerned with the order of the products.

Thanks

Ah simple_smile . Either way use a prefetch path and specify a sort clause, or call myProduct.SetCollectionParametersColors(0, sorter);

Frans Bouma | Lead developer LLBLGen Pro