Hi Walaa,
Thanks for your response.
The expression can not be moved to "Where" clause because there are 10 fields on CustomerBalance entity - and some needs to be updated by value, but others fields may not be changed...
For example:
- The entity contains "Activity" field - which updates all the time by "calculated value".
- The entity contains "HistoryHighestBalance" field - which updates only when calculated balance is more than existing database value in the same field.
- The entity contains "HistoryHighestActivityDate" field - which updates only when entered date is more than existing database value in the same field.
For example the following code updates "Activity" value always, but HistoryHighestBalance with IIF condition only.
var value = 1000; // Calculated Value
var entity = new CustomerBalanceEntity();
entity.Fields[CustomerBalanceFields.HistoryHighestBalance.FieldIndex].SetExpression (Functions.IIF(CustomerBalanceFields.HistoryHighestBalance > value, CustomerBalanceFields.HistoryHighestBalance, value));
entity.Fields[CustomerBalanceFields.Activity.FieldIndex].SetExpression(CustomerBalanceFields.Activity + value);
this.AdapterToUse.UpdateEntitiesDirectly(entity, new RelationPredicateBucket(CustomerBalanceFields.CustomerId == 1));
The code can be moved to separate SQL statements, but there are 5 other "HistoryHighest*" fields on the same entity and it will cause multiple database calls...
It's better to include "HistoryHighest*" fields on the same update statement to avoid multiple database calls. Currently, I manually added "DbFunctionCall" with "CASE WHEN END" statement, and it works as expected
I am not sure why Functions.IIF does not work in this instance. Please advise me.
Kind Regards,