Getting the IsDirty state of a property

Getting the IsDirty state of a property

Old forum URL: forums.lhotka.net/forums/t/4732.aspx


Piet Koole posted on Tuesday, April 22, 2008

I am using CSLA 3.5 and want to see which properties are dirty.
Because I only want to save the locally changed properties I have to find out which properties has changed locally. I do not want to compare to the database.

I want to accomplish that concurrent changes of other properties will not be overwritten.

I see that there is a IsDirty method in de FieldData, but I can't see were it is exposed.

Piet

RockfordLhotka replied on Tuesday, April 22, 2008

Hmm, that may be an oversight on my part. I think at one point I allowed your code to retrieve the actual FieldData object, but that was too liberal (breaks encapsulation). But in closing that down it may be that I didn't provide an alternative to get at the IsDirty value.

FieldDataManager should probably have a bool FieldHasChanged(IPropertyInfo) method. I'll add this to the wish list.

rsbaker0 replied on Tuesday, April 22, 2008

We're still on CSLA 3.0, and we implemented this ourself. It's not hard if you are using a code generator where you can easily modify the property setter code generated for your objects.

In our case, we have a "PropertyChanging" method that is called before the backing field for a property is set, and the property setters pass the prior value in as well as the new value. This allows the common BO base class to track individual property changes. At first glance, you'd think you could do the same thing with PropertyHasChanged(), except that the BO will still think it is dirty if the user changes the value back to the original. This might be OK for some applications, but we used whether the property has "really" changed in some validation rules.

RockfordLhotka replied on Tuesday, April 22, 2008

If I got it all right (I must confess I didn't test this scenario all the way through though) you should be able to replace the FieldData implementation with your own that could store the original value of the field and make IsDirty do a current<->original comparison.

RockfordLhotka replied on Tuesday, May 27, 2008

I've added a IsFieldDirty() method to FieldDataManager in the code in svn for 3.5.1, so that should address this need.

Copyright (c) Marimer LLC