Fetching an EntityCollection sorted by related object

Posts   
 
    
cds avatar
cds
User
Posts: 20
Joined: 01-Feb-2006
# Posted on: 17-Jun-2009 11:01:18   

Hi

Using LLBLGen 2.6 over SQL Server 2008, using the Adapter.

I'm trying to fetch an EntityCollection sorted by a related entity. I've seen a few posts on this, but I can't get it to work.

I have my two entities:

UserLogon and Professional. UserLogon has a FK reference to Professional, which has a Code property.

I want to fetch a collection of UserLogon entities ordered by their Professional.Code.

I can't find anything in the documentation on how to do this...

Can somebody point me in the right direction?

Thanks,

Craig

cds avatar
cds
User
Posts: 20
Joined: 01-Feb-2006
# Posted on: 17-Jun-2009 11:08:48   

Of course, as soon as I posted this, I figured it out.

Basically I do this:

var coll = new EntityCollection<UserLogonEntity>(); var path = new PrefetchPath2((int)EntityType.UserLogonEntity); var sort = new SortExpression(ProfessionalFields.Code | SortOperator.Ascending); var bucket = new RelationPredicateBucket(); bucket.Relations.Add(UserLogonEntity.Relations.ProfessionalEntityUsingFkProfessionalId); adapter.FetchEntityCollection(coll, bucket, 0, sort, path);

And it works!