Home
Help
Register
Log in

Search

 
   Active Threads  

You are here: Home > LLBLGen Pro > Bugs & Issues> SetExpression and IsDirty/IsChanged
 

Pages: 1
Bugs & Issues
SetExpression and IsDirty/IsChanged
Page:1/1 

  Print all messages in this thread  
Poster Message
Findev
User



Location:

Joined on:
08-Dec-2014 23:21:38
Posted:
100 posts
# Posted on: 21-Apr-2020 20:04:24.  
Hi,

LinqPad 5, LLBLGen v.5.6x

Noticed that if I do:
Code:

var e = new XYZ();
e.Fields[(int)XYZFieldIndex.DateValidFrom].SetExpression(GetUtcDateTimeOffset());
this.AdapterToUse.SaveEntity(e).Dump("isSaveOk");


where
Code:
GetUtcDateTimeOffset()
is
Code:

public static DbFunctionCall GetUtcDateTimeOffset()
{
    return new DbFunctionCall("SYSDATETIMEOFFSET", null);
}

then it prints true, but no actual query is executed. Seems like .SetExpression is not triggering entity to be "dirty", to fix this I either have to set some other property to some value then .SetExpression starts working or explicitly mark that field as changed:
Code:
e.Fields[(int)XYZFieldIndex.DateValidFrom].IsChanged = true;

Is it by design that it:
if some other property is modified then .SetExpression field(s) don't need explicit
Code:
.IsChange = true

if only .SetExpression is used, then it requires explicit
Code:
.IsChange = true
or for entity
Code:
e.IsDirty = true


Thank you!
  Top
daelmo
Support Team



Location:
Guatemala City
Joined on:
28-Nov-2005 23:35:24
Posted:
8137 posts
# Posted on: 22-Apr-2020 07:43:54.  
Hi Findev,

Findev wrote:

[code]
var e = new XYZ();
e.Fields[(int)XYZFieldIndex.DateValidFrom].SetExpression(GetUtcDateTimeOffset());
this.AdapterToUse.SaveEntity(e).Dump("isSaveOk");

This entity is new, Right? And you are only setting a field which is an expression, Right?

Findev wrote:
Is it by design that it:
if some other property is modified then .SetExpression field(s) don't need explicit
Code:
.IsChange = true

if only .SetExpression is used, then it requires explicit
Code:
.IsChange = true


Yes, this is expected, as you are not really modifying the entity, so it wouldn't be noticed as a change/modification.


David Elizondo
LLBLGen'ing (articles and code snippets) | linkedin | twitter
 
Top
Findev
User



Location:

Joined on:
08-Dec-2014 23:21:38
Posted:
100 posts
# Posted on: 22-Apr-2020 08:45:11.  
It's the same behavior if
Code:
e.IsNew = false;


Out of curiosity: why .SetExpression() doesn't trigger the change? In the end if some entity's property is modified or entity is marked as dirty then previously set expression still takes place meaning it is being tracked anyways.

Thank you!
  Top
Otis
LLBLGen Pro Team



Location:
The Hague, The Netherlands
Joined on:
17-Aug-2003 18:00:36
Posted:
38047 posts
# Posted on: 22-Apr-2020 10:41:13.  
The persistence engine of entity instances checks for whether an entity is dirty or whether an entity becomes dirty after a save of a related entity (because one of its fk fields gets a value synced). It doesn't check whether an expression is set on a field.

When an entity is dirty at the time of persisting it, it will be handed off to the query engine and at that moment it will be checked whether a field has an expression set.

The actual use case to do what you want is to use the UpdateEntitiesDirectly method: the entity passed in is expected to have fields set or expressions set on its fields and is passed as-is to the query engine: there the same code as the one which accepts an entity with changed fields, is handling it and producing an update query.

So if you want to have fields set based on an expression, you need to use the UpdateEntitiesDirectly method. The idea is that the entity you set the expression on isn't the only one changing hence the requirement to do it this way. That you can set an expression on a field in an entity is more a side effect of how the low level api works. In general you wouldn't use it this way but only through the UpdateEntitiesDirectly method.


Frans Bouma
LLBLGen Pro / ORM Profiler Lead Developer | Blog | Twitter
 
Top
Findev
User



Location:

Joined on:
08-Dec-2014 23:21:38
Posted:
100 posts
# Posted on: 22-Apr-2020 12:03:24.  
Thank you for your response.

5-6 years ago I had snippets which set the .IsChanged to true. Later on, some of those where refactored (+removed IsChanged assignments) and the result was still the same, yet, if I remember correctly originally I had to set the changed flag to get the desired result. Of course during the refactoring other things got updated too, thus can't say whether the run-time has changed that behavior or, most probably, my own refactoring side-effect Regular Smiley Speaking of which: after the explanation I understand why you call it like that, but great it exists. For the task at hand I'm saving a new entity and certain fields require some date and time arithmetic using db functions.

Thanks again! Regular Smiley
  Top
Pages: 1  


Powered by HnD ©2002-2007 Solutions Design
HnD uses LLBLGen Pro

Version: 2.1.12172008 Final.