Newbie Sort on a PrefetchPathElement query

Posts   
 
    
CharlieOz1
User
Posts: 3
Joined: 05-Jul-2006
# Posted on: 11-Jul-2006 06:32:48   

Hi,

I would appreciate some help with the following

I have a PrefetchPathElement which has been code generated.

I need to sort the results. I have tried:

SortExpression sort = new SortExpression(); sort.Add(SortClauseFactory.Create(LeadSourceFieldIndex.Name, SortOperator.Ascending));

return new PrefetchPathElement( new Simbient.NatureCare.Objects.CollectionClasses.LeadSourceCollection(), PersonEntity.Relations.LeadSourceEntityUsingLeadSourceId, (int)Simbient.NatureCare.Objects.EntityType.PersonEntity, (int)Simbient.NatureCare.Objects.EntityType.LeadSourceEntity, 0, sort, null, null, "LeadSource", RelationType.ManyToOne);

where LeadSourceFieldINdex is the field I wish to sort on.

So far no joy! Your help appreciated as I am new to LLBL and I am on a deadline (aren't we all).

I understand the code snippet will be lost if regenerated.

Thanks Charlie

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 11-Jul-2006 08:06:02   

I suppose this is m-1 relation between Person Entity and LeadSource Entity. So each Person is pointing to one Lead Source.

Then I suppose you want to sort the returned Person entities on the Name of their LeadSource. am I correct?

Then you may sort the collection at client side as stated in the following thread: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=5242

Or you may want to have the sort done at the database side. Then you would have to join the LeadSource (add an EntityRelation from PersonEntity to LeadSourceEntity to the fetch method). Then use a SortExpression (a sort clause of LeadSource->Name) in the fetch Method.

I understand the code snippet will be lost if regenerated

Why don't you have the sorting written in your code that does the fetching?

The code snippet you showed will return a PrefetchPathElement with a sortExpression, which is used to sort the entities fetched with the PrefetchPathElement (sort the related entities i.e. sort the LeadSource Entities returnd which would be only one entity)