EntityCollection sort

Posts   
 
    
Fabrice
User
Posts: 180
Joined: 25-May-2004
# Posted on: 01-Mar-2006 14:12:50   

Hi all I need to sort a EntityCollection on several fields. I know how to do it on 1 field, but is there a way to do it on several fields ? Or any idea on how toh ack the template that generate the EntityCollection class ?

I'm using Adapter scenario Thanks a lot

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 01-Mar-2006 15:02:03   

A client side sort over multiple columns is currently not supported.

Please refer to the following thread: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=4329

Fabrice
User
Posts: 180
Joined: 25-May-2004
# Posted on: 01-Mar-2006 15:51:58   

You like to give links simple_smile I've allready read, and in my previous post the question was :

Or any idea on how toh ack the template that generate the EntityCollection class ?

And I've read another thread where it say it should be possible, but I don't see how as I can't reproduce the example: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=2764&HighLight=1

[edit]wrong link

JimHugh
User
Posts: 191
Joined: 16-Nov-2005
# Posted on: 01-Mar-2006 17:02:48   

You can sort it during the fetch as follows:


Dim sort As New SortExpression(ContactFields.LastName Or SortOperator.Ascending)
sort.Add(ContactFields.FirstName Or SortOperator.Ascending)
adapter.FetchEntityCollection(ecContact, bucket, 0, sort, nothing)

Assumes VS2005 and 1.2005.1

JimHugh
User
Posts: 191
Joined: 16-Nov-2005
# Posted on: 01-Mar-2006 17:05:08   

You should also be able to sort it using a BindingSource or DataView


    ' Filter the items to show contacts who are owners.
    BindingSource1.Filter = "ContactTitle='Owner'"
    ' Sort the items on the company name in descending order.
    BindingSource1.Sort = "Country DESC, Address ASC"

be sure to set SupportsSorting = true on the entitycollection.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39930
Joined: 17-Aug-2003
# Posted on: 01-Mar-2006 17:09:01   

Fabrice wrote:

You like to give links simple_smile I've allready read, and in my previous post the question was :

Or any idea on how toh ack the template that generate the EntityCollection class ?

And I've read another thread where it say it should be possible, but I don't see how as I can't reproduce the example: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=2764&HighLight=1

[edit]wrong link

In-memory sorts of entitycollections is currently (1.0.2005.1) limited to a single property, as IBindingList sorts on a single property and the sort is an implementation of IBindingList.ApplySort().

In v2, multi-property sorts are possible using SortExpression objects directly on the entityview objects. Till then, single property sorts are the only thing you have, or you have to use a grid which supports multi-column sorts like JanusGrid.

ps: Fabrice, please be patient. We all try to help you here, no need to critisize offered help.

Frans Bouma | Lead developer LLBLGen Pro
Fabrice
User
Posts: 180
Joined: 25-May-2004
# Posted on: 01-Mar-2006 17:09:39   

JimHugh wrote:

You can sort it during the fetch as follows:


Dim sort As New SortExpression(ContactFields.LastName Or SortOperator.Ascending)
sort.Add(ContactFields.FirstName Or SortOperator.Ascending)
adapter.FetchEntityCollection(ecContact, bucket, 0, sort, nothing)

Assumes VS2005 and 1.2005.1

I speak about in-memory sort, not sql. But ok, I've make something very bad, but as it's not used very often, it can stay like this sometime simple_smile

ArrayList    listOfEntities = new ArrayList(myEntityCollection);
listOfEntities.Sort(new myCustomComparer);

I know, it's horrible frowning

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39930
Joined: 17-Aug-2003
# Posted on: 01-Mar-2006 17:10:24   

JimHugh wrote:

You should also be able to sort it using a BindingSource or DataView


    ' Filter the items to show contacts who are owners.
    BindingSource1.Filter = "ContactTitle='Owner'"
    ' Sort the items on the company name in descending order.
    BindingSource1.Sort = "Country DESC, Address ASC"

be sure to set SupportsSorting = true on the entitycollection.

You're sure that works on an entitycollection? (haven't tried it), as the filter and sorter are likely to be passed to the DataView object, and an entitycollection doesn't support these properties.

Frans Bouma | Lead developer LLBLGen Pro
Fabrice
User
Posts: 180
Joined: 25-May-2004
# Posted on: 01-Mar-2006 17:12:31   

Otis wrote:

In-memory sorts of entitycollections is currently (1.0.2005.1) limited to a single property, as IBindingList sorts on a single property and the sort is an implementation of IBindingList.ApplySort().

In v2, multi-property sorts are possible using SortExpression objects directly on the entityview objects. Till then, single property sorts are the only thing you have, or you have to use a grid which supports multi-column sorts like JanusGrid.

Ok, I can let the horrible solution like that unitll v2

Otis wrote:

ps: Fabrice, please be patient. We all try to help you here, no need to critisize offered help.

Well, I've not criticize, I've put a smiley ! simple_smile Thank you for your help (all).

JimHugh
User
Posts: 191
Joined: 16-Nov-2005
# Posted on: 01-Mar-2006 17:17:17   

Otis wrote:

You're sure that works on an entitycollection? (haven't tried it), as the filter and sorter are likely to be passed to the DataView object, and an entitycollection doesn't support these properties.

No, I'm not sure cry Hence my disclaimer of "should" wink

I based my comment on my prior experience with datatables and dataviews where I have used that method.

Sorry for the misinformation.

Sam avatar
Sam
User
Posts: 95
Joined: 30-Jun-2004
# Posted on: 01-Mar-2006 17:58:43   

    ' Filter the items to show contacts who are owners.
    BindingSource1.Filter = "ContactTitle='Owner'"
    ' Sort the items on the company name in descending order.
    BindingSource1.Sort = "Country DESC, Address ASC"

My experience is that neither work with EntityCollections. Setting Supports Sorting/Filtering does nothing.