Private Backing Field - FieldManager.IsDirty()

Private Backing Field - FieldManager.IsDirty()

Old forum URL:

keithv posted on Thursday, February 27, 2014

I am seeing a behavior I do not understand with BusinessBase. When changing a property with a private backing field BusinessBase.IsDirty is true but FieldManager.IsDirty() = false.

Here is my property:

public static readonly PropertyInfo<bool> HasImageProperty = RegisterProperty<bool>(c => c.HasImage, RelationshipTypes.PrivateField);

[NotUndoable, NonSerialized]
protected bool _HasImage = false;
public bool HasImage
            get { return GetProperty(HasImageProperty, _HasImage); }
            set { SetProperty(HasImageProperty, ref _HasImage, value); }



// At This Point:
// HasImage = false
// base.IsDirty = false;
// FieldManager.IsDirty() = false;

HasImage = true;

// At This Point:
// HasImage = true
// base.IsDirty = true
// FieldManager.IsDirty() = false; // How??


This has me very confused. Isn't BusinessBase.IsDirty driven off of FieldManager.IsDirty?

For some background the business scenario I am trying to work out is having required business rules based on a child list. If an item is added to the child list I want three other non-list properties on the parent to be required. Since business rules do not get executed when items are added/removed I added the rules to a new boolean property HasImage and set HasImage in the OnChildChanged override. When HasImage = true the three non-list properties are required. Only if you add an item to the list and then remove it the item stays marked as IsDirty since HasImage has changed. I cannot work out how to have a property with business rules that does not effect IsDirty.

Thank you!


JonnyBee replied on Thursday, February 27, 2014


FieldManager only has knowledge of the status on "managed" properties - not properties with private backing fields. 

And so BusinessBase has a private field for _isDirty and this is the actual code:

[Display(AutoGenerateField = false)]
public virtual bool IsDirty
  get { return IsSelfDirty || (_fieldManager != null && FieldManager.IsDirty()); }

public virtual bool IsSelfDirty {   get { return _isDirty; } }

Copyright (c) Marimer LLC