.SortClause and Prefetching on Self-Servicing

Posts   
 
    
mshe
User
Posts: 167
Joined: 02-Feb-2006
# Posted on: 02-Nov-2007 00:09:11   

If I have a self servicing collection i.e.:

CountryCollection(0).States

Can I assign a SortClause to the states before iterating thorugh it.

i.e.

CountryCollection(0).States.SortClause = MySortClause?

When I do this, the SortClause doesn't take effect. Rather, I need to call GetMulti with a sort?

Any way to avoid this? It just seems cleaner if I can assign the SortClause directly.

Thanks!

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 02-Nov-2007 10:33:48   

You mean you want to sort it in Memory?

You may use the collection Sort() methog.

CountryCollection(0).States.Sort(...);
mshe
User
Posts: 167
Joined: 02-Feb-2006
# Posted on: 02-Nov-2007 17:17:32   

Walaa wrote:

You mean you want to sort it in Memory?

You may use the collection Sort() methog.

CountryCollection(0).States.Sort(...);

I was hoping to do it server side on the SQL server :-)

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 03-Nov-2007 05:29:11   

mshe wrote:

Walaa wrote:

You mean you want to sort it in Memory?

You may use the collection Sort() methog.

CountryCollection(0).States.Sort(...);

I was hoping to do it server side on the SQL server :-)

We thought you wanted in-memory sorting simple_smile

And yes, I think that is possible... I never used this before, but I tested today and seems to work very well:

CustomerEntity myCustomer = new CustomerEntity("ALFKI");

// creating the sorter
SortExpression sorterToOrders = new SortExpression();
sorterToOrders .Add(OrdersFields.Freight | SortOperator.Ascending);

// specifications for the sorting of the resultset. When not specified, no sorting is applied. 
customer.SetCollectionParametersOrders(0, sorterToOrders );

// orders sorted...
customer.Orders
David Elizondo | LLBLGen Support Team
mshe
User
Posts: 167
Joined: 02-Feb-2006
# Posted on: 03-Nov-2007 06:18:47   

daelmo wrote:

CustomerEntity myCustomer = new CustomerEntity("ALFKI");

// creating the sorter
SortExpression sorterToOrders = new SortExpression();
sorterToOrders .Add(OrdersFields.Freight | SortOperator.Ascending);

// specifications for the sorting of the resultset. When not specified, no sorting is applied. 
customer.SetCollectionParametersOrders(0, sorterToOrders );

// orders sorted...
customer.Orders

The SortClause just seemed to obvious, so that's the secret! SetCollectionParametersEntity. Thanks!