CSLA .NET

From Rockford Lhotka's Expert C# 2005 and VB 2005 Business Objects books

Welcome to CSLA .NET Sign in | Join | Help
in Search

Getting the IsDirty state of a property

Last post 05-27-2008, 4:23 PM by RockfordLhotka. 4 replies.
Sort Posts: Previous Next
  •  04-22-2008, 7:02 AM 23002

    Getting the IsDirty state of a property

    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
  •  04-22-2008, 8:04 AM 23015 in reply to 23002

    Re: Getting the IsDirty state of a property

    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.


    Rocky
  •  04-22-2008, 9:05 PM 23058 in reply to 23002

    Re: Getting the IsDirty state of a property

    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.

  •  04-22-2008, 9:17 PM 23059 in reply to 23058

    Re: Getting the IsDirty state of a property

    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.
    Rocky
  •  05-27-2008, 4:23 PM 23811 in reply to 23059

    Re: Getting the IsDirty state of a property

    I've added a IsFieldDirty() method to FieldDataManager in the code in svn for 3.5.1, so that should address this need.
    Rocky
View as RSS news feed in XML

Please contact Magenic for your .NET consulting and CSLA .NET mentoring needs.
Please consider making a donation to help support the ongoing development of CSLA .NET.

Make donation through PayPal - it's fast, free and secure!
Why donate?
Powered by Community Server, by Telligent Systems