IsDirty flag

Posts   
 
    
Posts: 18
Joined: 21-Mar-2011
# Posted on: 25-Apr-2011 10:10:15   

Hello, in our application after getting entity from database, we bind its ingormatiom to form. When saving entity, we collect all form information (from textboxes for example), and set entity's properties with collected info. For example, entity.EntityName=txtName.text. I found out, that when initial value equals to current value, entity.IsDirty == true after last action. Is it possible to check initial and currnet values of object so that IsDirty flag would be right when we save entity? So, at first we got entity and bind all controls to entity's properties. Second, we read all binded controls' values and set back entity's properties. And would like to check - if values changes - i update entity, if all properties' values are equal - i do nothing.

Thanks

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 25-Apr-2011 11:02:35   

Are you setting values back to the same entity instance you have fetched from the database. or you re-construct a new instance using the PK?

Is this a win app or a web app? Why don't you use databinding?

Which LLBLGen Pro version are you using?

Posts: 18
Joined: 21-Mar-2011
# Posted on: 25-Apr-2011 12:59:24   

1) i am setting values back to the same entity instance you have fetched from the database;

2) this is win app; 3) (technical requirements)

4) LLBLGen Pro version 2.6.

Posts: 18
Joined: 21-Mar-2011
# Posted on: 25-Apr-2011 13:00:05   

we are also using stored procedures for some instances

Posts: 18
Joined: 21-Mar-2011
# Posted on: 25-Apr-2011 14:28:09   

maybe i can overwrite method SetValue for entities properties?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 25-Apr-2011 16:02:21   

The thing is, databinding won't have set the field, unless you have changed to some temp value then back again to the original value.

But now, since you set the fields yourself, the IsChanged for the field is set to true, and consequently the IsDirty flag is set too.

You can do a check first and skip setting the value of a field if it matches the existing one. You can do this in the routine setting the values into the fields, and you can do this inside the Set-ter of each the Field property.