Update Expressions on a nullable field

Posts   
 
    
tnero
User
Posts: 18
Joined: 09-Apr-2013
# Posted on: 07-Jun-2016 06:51:38   

In 4.2 (or 5 since i will upgrade soon), how can I do a direct entity update on a nullable field?

The field 'foo' is nullable therefore adding to it - remains 0 unless isnull() is used

sql required:

update tablename set foo = isnull(foo,0) + 1.50

current sql:

update tablename set foo = foo + 1.50

current llblgen which causes it to remain null:

fooinstance.Fields[(int)TableNameFieldIndex.Foo].ExpressionToApply = (TableNameFields.Foo+ 1.50);

thank you!

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 07-Jun-2016 14:41:55   

You should put the ISNULL in a DBFunctionCall. See the examples in the link.

David Elizondo | LLBLGen Support Team
tnero
User
Posts: 18
Joined: 09-Apr-2013
# Posted on: 08-Jun-2016 04:41:03   

Great! thank you.

In case anyone needs the code would be:

fooinstance.Fields[(int)TableNameFieldIndex.Foo].ExpressionToApply =  new DbFunctionCall("ISNULL({0},0) + {1}", new object[] { TableNameFields.Foo, 1.50 });
daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 08-Jun-2016 06:03:13   

Nice! Thanks for sharing your solution. sunglasses

David Elizondo | LLBLGen Support Team