Entity Collection Sort: Sort on Related Fields

Posts   
 
    
caseyry
User
Posts: 79
Joined: 25-Feb-2005
# Posted on: 25-Jan-2006 15:40:55   

Hi --

I looked at the documentation and searched this forum and I couldn't figure out whether or not this is possible.

Can you sort a filled entity collection on a related field?

For example, I have a collection of members where each member has a company. Can I sort on member.Company.CompanyName?

I wasn't sure if this was possible with using a "Custom Comparer."

Thanks, -Ryan Casey

gabrielk avatar
gabrielk
User
Posts: 231
Joined: 01-Feb-2005
# Posted on: 25-Jan-2006 17:21:00   

Hi,

You could create a property on your member entities which will retrieve:

"this.Company.CompanyName"

And fir the CollectionClass set: SupportsSorting = True;

then: (Members would be an instance of the collectionclass) Members.Sort("CompanyName",ListSortDirection.Ascending,null);

Maybe this is ineffecient and should be handled different, if please tell me, because I use this, incombination with PrefetchPaths (In this case to prefetch the companies)

greets, Gab

caseyry
User
Posts: 79
Joined: 25-Feb-2005
# Posted on: 25-Jan-2006 17:43:14   

gabrielk wrote:

You could create a property on your member entities which will retrieve:

"this.Company.CompanyName"

And fir the CollectionClass set: SupportsSorting = True;

then: (Members would be an instance of the collectionclass) Members.Sort("CompanyName",ListSortDirection.Ascending,null);

Good idea, thanks!