Order of related entities

Posts   
 
    
JayBee
User
Posts: 282
Joined: 28-Dec-2006
# Posted on: 26-Sep-2007 15:58:03   

Hi,

I am using SelfService.

I have two entities with a 1:n relation, e.g Adress and AdressDetail both with their own PK. When I retrieve an Adress entity, I can access the AdressDetail entities directly via the relation attribute. What is the order in which the AdressDetail entities are made available via the relation attribute?

e.g.

AdressEntity adress = new AdressEntity(123); foreach (AdressDetailEntity adressDetail in adress.AdressDetail) { Console.Writeline(adressDetail.text); }

Is there a fixed order in the displayed lines, for instance the PK of the AdressDetail entity?

Kind regards,

Jan

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 26-Sep-2007 16:11:56   

Entities are ordered as returned from the database. If you want to provide a specific ordering, try the following:

SortExpression sorter = new SortExpression(AdressDetailFields.AnyField | SortOperator.Ascending)

PrefetchPath prefetchPath = new PrefetchPath((int)EntityType.CustomerEntity);
prefetchPath.Add(AdressEntity.PrefetchPathAdressDetails, 0, null, null, sorter);

AdressEntity adress = new AdressEntity(123, prefetchPath);
foreach (AdressDetailEntity adressDetail in adress.AdressDetail)
{
     Console.Writeline(adressDetail.text);
}
JayBee
User
Posts: 282
Joined: 28-Dec-2006
# Posted on: 26-Sep-2007 16:46:19   

Thanks Walaa, I'll try something like that.

However, I do not think that this kind of logic should be present in the application layer. It should be part of the Business Logic Layer. When one retrieves an adress, the adress lines will always be processed in the same way.

Perhaps I should raise a feature request to have that kind of functionality added to the designer? E.g. offer the possibility for fields mapped on relations to specify the order of the entity collection.

Kind regards,

Jan

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 26-Sep-2007 17:25:49   

I think you may insert the sorting code into the EntityClass code. I've found the following related thread: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=5912

JayBee
User
Posts: 282
Joined: 28-Dec-2006
# Posted on: 26-Sep-2007 21:43:28   

I temporarely solved it by using a client side sort.

I looked at your link and guess that might solve it too. I still think it would be nice to be able to do this in the designer.

Jan