(llblgen 1.0) default sort order for self-servicing collections

Posts   
 
    
wtijsma
User
Posts: 252
Joined: 18-Apr-2006
# Posted on: 26-Jul-2006 15:25:47   

Hi,

Is it possible (without altering the templates) to change the default sort order for lazy-loaded related collections in the self-servicing scenario?

Suppose I have a customer-invoice one-to-many relation that by default has to be sorted on the 'Ordinal' field of the invoice, and I access my invoices like this:


CustomerEntity customer = new Customer(1);
InvoiceCollection invoices = customer.Invoices;

I'm still using LLBLGen 1.0 targeting .NET 2.0 using partial classes

Thanks...

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 26-Jul-2006 16:26:34   

Use SetCollectionParametersInvoices in CustomerEntity for this simple_smile

Frans Bouma | Lead developer LLBLGen Pro
wtijsma
User
Posts: 252
Joined: 18-Apr-2006
# Posted on: 26-Jul-2006 17:18:46   

sunglasses

Thx...

Which would be the best override/event to set this parameter by default, OnFetch?

        ///<summary>
        ///
        ///         Called right before the entity's Fetch logic is started. 
        ///         
        ///</summary>
        ///
        protected override void OnFetch()
        {
            SortClause sortClause = new SortClause(InvoiceFields.Ordinal, SortOperator.Ascending);
            SortExpression sortExpression = new SortExpression(sortClause);
            this.SetCollectionParametersTemplateSteps(0,sortExpression);
            base.OnFetch();
        }

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 26-Jul-2006 18:22:31   

It depends if you want to sort them at client side using the EntityCollection.Sort() method. Or you want them sorted when fetched from the database.

OnFetch seems a good candidate for the second case, but take care it would be executed every time you fetch the entity.

wtijsma
User
Posts: 252
Joined: 18-Apr-2006
# Posted on: 26-Jul-2006 20:12:28   

Walaa wrote:

It depends if you want to sort them at client side using the EntityCollection.Sort() method. Or you want them sorted when fetched from the database.

OnFetch seems a good candidate for the second case, but take care it would be executed every time you fetch the entity.

I see, I do prefer a server side sort.

Preferably I'd do it in the constructor, but I can't override the constructor since they're in the generated partial class part.

Walaa, can you please advise which method would be better? otherwise I'll stick with OnFetch.

wtijsma
User
Posts: 252
Joined: 18-Apr-2006
# Posted on: 07-Aug-2006 21:11:18   

Otis wrote:

Use SetCollectionParametersInvoices in CustomerEntity for this simple_smile

Is there a similar method to add a standard predicate (filter) for these related methods, for example to filter out all entities where deleted=1?

Thx

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 08-Aug-2006 11:31:06   

No there's no such a method. You can specify the filter to a GetMulti... () overload though, which will fill the related collection, so for example you can call myCustomer.GetMultiOrders(...) to fill myCustomer.Orders and pass a filter to the GetMultiOrders overload to filter the rows you want.

Frans Bouma | Lead developer LLBLGen Pro
wtijsma
User
Posts: 252
Joined: 18-Apr-2006
# Posted on: 15-Aug-2006 17:49:04   

Otis wrote:

No there's no such a method. You can specify the filter to a GetMulti... () overload though, which will fill the related collection, so for example you can call myCustomer.GetMultiOrders(...) to fill myCustomer.Orders and pass a filter to the GetMultiOrders overload to filter the rows you want.

Thanks!