ExpressionToApply doesnot reset after field change

Posts   
 
    
Rosacek
User
Posts: 155
Joined: 18-Mar-2012
# Posted on: 17-Apr-2016 15:24:48   

LLBLGEN v4.2.16.311 , Adapter

Hi, I set field.ExpressionToApply to some function, then save entity. After that I change fied value by databinding to nothing or to any value and save entity.

I expect that new field value is saved by UPDATE. But I can see that ExpressionToApply is used again in SQL UPDATE rage

Is it behavior OK? I would say that after field value change then field.ExpressionToApply should be set to Nothing automatically.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 18-Apr-2016 03:11:42   

Rosacek wrote:

I would say that after field value change then field.ExpressionToApply should be set to Nothing automatically.

No, that is not that obvious. If you are using the same entity instance, you should set ExpressionToApply to null/Nothing.

David Elizondo | LLBLGen Support Team
Rosacek
User
Posts: 155
Joined: 18-Mar-2012
# Posted on: 18-Apr-2016 11:29:43   

The question was, why LLBL is not doing that automatically after changing field value? Do you agree taht changing value means I want to save this value into SQL server? Why should I test manually right befeore changing field value if there is ExpressionToApply then set it to nothing? Does not make sense to me

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39613
Joined: 17-Aug-2003
# Posted on: 18-Apr-2016 16:58:59   

The expression to apply for saving is more of a way to get things into the query system for persistence, so it's mainly meant for: you set it, you use it to execute a query, then you discard the entity. If you keep it around, then you have to clear it manually, as it is what David said: it's ambiguous what to do: clear it always or leave it as is. For its intended use case it's discarded anyway, so we don't clear things for you.

The value in the field is actually ignored when expression to apply is set, setting the field doesn't trigger logic to reset that expression.

Frans Bouma | Lead developer LLBLGen Pro
Rosacek
User
Posts: 155
Joined: 18-Mar-2012
# Posted on: 18-Apr-2016 18:18:21   

Bad news for me rage

Well, what is the best place to reset ExpressionToApply to nothing? Override SaveEntity and SaveEntityCollection in DataAdapter and set there ExpressionToApply=Nothing? Or is there better place?

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 19-Apr-2016 00:39:17   

Not sure how generalized you want it to be, which will affect the decision to clear the expression in the business logic or the lower layers.

One suggestion would be to use the ValidateEntityBeforeSave in a validator class, to check if the entity.Fields is not new, and then clear the expression. And then you can decide either to inject this validator into all instances created of this entity type, or just set it in specific locations, either by system wide DI , or by using DI Scopes

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39613
Joined: 17-Aug-2003
# Posted on: 19-Apr-2016 10:23:47   

If you want to have it cleared when a value is set in the entity, you can override in a partial class of CommonEntityBase (so it works for all entities): OnSetValueComplete(fieldIndex)

In there you simply set the ExpressionToApply property of the field on index FieldIndex to null

Alternatively you can clear things in a partial class of DataAccessAdapter and override OnSaveEntityComplete.

Frans Bouma | Lead developer LLBLGen Pro
Rosacek
User
Posts: 155
Joined: 18-Mar-2012
# Posted on: 19-Apr-2016 10:25:31   

Yes, this makes sense. Thanks simple_smile