Sorting EntityCollection using custom IComparer

Posts   
 
    
William
User
Posts: 37
Joined: 05-Oct-2005
# Posted on: 05-Oct-2005 22:14:42   

Hello Everyone,

I've been enjoying LLBL and this forum for about 6 months now, but this is my first post.

Yesterday I ran into a problem where I wanted to do a complex, client-side sort on 3 fields in an entity. I tried using a custom IComparer class in the EntityCollection.Sort() method, but the method only sends the specified field into the Comparer, not the entire entity so I couldn't do the complex sort I wanted.

I got around this by copying all the entity objects into an ArrayList and then calling the .Sort() on this using my custom Comparer and it worked fine; for parameters I get two entity objects that use to decide which is greater or lesser.

Am I missing something in LLBL or is this an improvement that we're scheduled to get?

Thanks in advance,

William

William
User
Posts: 37
Joined: 05-Oct-2005
# Posted on: 05-Oct-2005 23:12:42   

I just looked through the threads from the last few days and I saw one where a question similiar to mine was asked by BeauButton.

Paul.Lewis responded that solutions could be found in the "Best Practices" and "Using the entity collection classes" sections of the help docs and that:

The examples only show sorts on a single attribute, but you should be able to expand the sort to multiple columns.

I looked there and I still don't see any way you can specify more than one column on a sort, especially when the parameter list includes the option for only entering the name of a single column.

Again, am I missing something?

Thanks again,

William

William
User
Posts: 37
Joined: 05-Oct-2005
# Posted on: 06-Oct-2005 00:17:56   

Sorry, I should also mention I'm using C# with the Adapter method.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39930
Joined: 17-Aug-2003
# Posted on: 06-Oct-2005 10:33:02   

I think Paul assumed a server-side sort.

A client side sort over multiple columns is currently not supported. Your idea is neat, but currently the code indeed sorts on field values, using the comparer (or a default comparer) specified. An enhancement for this is planned for 2.0 where object views are planned for entity collections, which allow you to filter and sort an entity collection using normal predicates and sortexpressions (like Linq, but ... different wink ).

Frans Bouma | Lead developer LLBLGen Pro