Using ExpressionToApply with UpdateEntitiesDirectly

Posts   
 
    
saggett
User
Posts: 50
Joined: 12-Nov-2007
# Posted on: 21-Nov-2008 15:38:22   

Running v2.6, C#, Adapter pattern, compiling for .NET 3.5:

I've been trying to write an expression for use in a call to UpdateEntitiesDirectly. However I can only produce the expression I want by writing it as a DbFunctionCall, like so:


var adapter = new DAL.DatabaseSpecific.DataAccessAdapter();
var bucket = new RelationPredicateBucket();
bucket.Relations.Add(SpecialPriceEntity.Relations.ProductEntityUsingProductId);
var spUpdate = new SpecialPriceEntity();
spUpdate.Fields[(int) SpecialPriceFieldIndex.IsSentToBaan].ExpressionToApply =
    new DbFunctionCall("CASE {0} WHEN 'TRUE' THEN NULL WHEN 'FALSE' THEN 'FALSE' END", new object[] {ProductFields.IsQonly});
adapter.UpdateEntitiesDirectly(spUpdate, bucket);

Is there any way I can write it using the LLBLGen Expression syntax, something like:


var adapter = new DAL.DatabaseSpecific.DataAccessAdapter();
var bucket = new RelationPredicateBucket();
bucket.Relations.Add(SpecialPriceEntity.Relations.ProductEntityUsingProductId);
var spUpdate = new SpecialPriceEntity();
spUpdate.Fields[(int) SpecialPriceFieldIndex.IsSentToBaan].ExpressionToApply =
    (ProductFields.IsQonly == true ? DbNull.Value : false);
adapter.UpdateEntitiesDirectly(spUpdate, bucket);

As this is a lot more readable and easier to maintain.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 21-Nov-2008 19:26:14   

Hi saggett,

That's no possible directly, as no mapping exists between the ternary construct and some sql query text. The default expression usage for updates are addressed here.

You have two options:

A. Write two update actions with different filters: one for ProductFields.IsQonly == true and one for ProductFields.IsQonly == false.

B. Use your DBFunctionCall approach.

David Elizondo | LLBLGen Support Team