COALESCE

Posts   
 
    
TogasPoon
User
Posts: 42
Joined: 09-Feb-2006
# Posted on: 31-Oct-2007 16:43:53   

How would I created this sort using LLBLgen

ORDER BY COALESCE(DeliveryDate,ReturnDate) DESC

Self Serving .net 2.0

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 31-Oct-2007 17:18:57   

COALESCE is a database function.

So you can use LLBLGen Pro DBFunction calls to retunr the appropriate Expression which can be set to the Field passed to the Sort Expression.

ref: LLBLGen Pro's Manual "Using the generated code -> Calling a database function"

TogasPoon
User
Posts: 42
Joined: 09-Feb-2006
# Posted on: 31-Oct-2007 18:13:34   

I tried this but it doesn't compile

dsOTS.SorterToUse = New SortExpression(New DbFunctionCall("COALESCE", New Object() {OrderTrackingViewFields.DeliveryDate,  OrderTrackingViewFields.ReturnDate}) Or SortOperator.Descending)

Any suggestions?

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 01-Nov-2007 10:05:23   

The new sort expression expects an EntityField. would you please try the following?

EntityField myField = OrderTrackingViewFields.DeliveryDate //any field will do.
myField.ExpressionToApply = New DbFunctionCall("COALESCE", New Object() {OrderTrackingViewFields.DeliveryDate, OrderTrackingViewFields.ReturnDate})
dsOTS.SorterToUse = New SortExpression(myField Or SortOperator.Descending)