Is it somehow possible to always mark a field dirty when set?

Posts   
 
    
AlexP
User
Posts: 17
Joined: 24-Jan-2020
# Posted on: 23-Nov-2023 10:05:28   

Is it somehow possible to always mark a field dirty when set? Even when it's set with the same value?

Imagine something like this:

class PeriodEntity
{
    public long Id {get;set;}
    public DateTime StartDate {get;set;}
    public DateTime EndDate {get;set;}
}

When 2 threads (on different machines) are setting the Start and End date (one sets a new Start date, and the other a new End date) it can happen that the Start date is after the End date. This can be prevented with a constraint but the behavior that we want is; "The last one that commits wins".

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39760
Joined: 17-Aug-2003
# Posted on: 23-Nov-2023 11:29:26   

1) please don't post support requests in General Chat.
2) I've moved this to LLBLGen Pro Runtime Framework but not sure if this is about our framework or e.g. Entity Framework as you post a poco class and our runtime doesn't support pocos

So a bit more information is required to answer your question.

Frans Bouma | Lead developer LLBLGen Pro
AlexP
User
Posts: 17
Joined: 24-Jan-2020
# Posted on: 24-Nov-2023 08:51:27   

Otis wrote:

1) please don't post support requests in General Chat.
2) I've moved this to LLBLGen Pro Runtime Framework but not sure if this is about our framework or e.g. Entity Framework as you post a poco class and our runtime doesn't support pocos

So a bit more information is required to answer your question.

  1. Whoops sorry simple_smile my error.

  2. It's true LLBLGen doesn't support Poco's I didn't want to write out the entire entity class.

I'm encountering a scenario where I need a specific entity column to always be updated, regardless of whether its value changes. The current behavior of the framework doesn't mark an entity field as 'dirty' or 'changed' if the new value assigned is the same as the existing value. While this optimization might be beneficial in most cases, it creates challenges for our specific use case. In our project, we're working with a substantial code base that, admittedly, does not always follow ideal architectural practices which is an important part of the challenge we're currently facing.

To illustrate, consider 2 related properties eg. StartDate and EndDate (other situations exist) of an entity. Even when any of the dates is set to the same value it already holds, we need it to be treated as updated when Save/SaveAsync is invoked. This is crucial because the current behavior can lead to inconsistencies in our system that aren't always manageable through database constraints alone.

Is there a way to override or customize this behavior within LLBLGen? Specifically, we're looking for a method to flag certain entity fields so that they're always updated in the database, irrespective of value changes. Any guidance or workarounds to achieve this would be greatly appreciated.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39760
Joined: 17-Aug-2003
# Posted on: 25-Nov-2023 09:48:06   

In a partial class of the entity class (or CommonEntityBase, if you want to have a fallback function for many entities which share e.g. the same fields) you can override OnSetValueComplete. This method is called at the end of SetValue, despite whether the field's value is actually set or not (e.g. in case when the value is the same).

In that override, you can check if the field is marked dirty in the Fields object, and if not, set it to Dirty manually.

Frans Bouma | Lead developer LLBLGen Pro