title: (is there an) Easy way to check if property in (complex) pocomodel has changed?
body: <p>I was wondering if there is an 'easy'/good way to check if a property has changed. Like in the hierarchy below when Child.Name has changed (isDirty) I would like to know. </p>
  
  <pre><code>GrantParent
  - Parent
  -- Child
  </code></pre>
  
  <p>In my current situation I need to navigate through the model to see if anything has changed. </p>
  
  <p>ps: I'm using <code>IChangeTracking</code>. </p>
  
  <p>Been thinking about caching a hash of the serialized object. (too slow?)</p>
  
  <p>Or creating changedevent which call's the parent until it reaches the grantparent. (chatty?)</p>
  
  <pre><code>  public class Parent: BaseEntity
    {
      private Child _child;
      public Child Child
      {
        get { return _child; }
        set { _child = value; OnPropertyChanged("Child"); }
      }
    }
  
    public class Child : BaseEntity
    {
      private  int _id;
      public int Id {
        get { return _id; }
        set { _id = value; OnPropertyChanged("Id"); }
      }
    }
  
  
  
   [DataContract]
    [Serializable]
    public abstract class BaseEntity : INotifyPropertyChanged
    {
      protected BaseEntity()
      {
        PropertyChanged += PropertyChangedEventHandler;
      }
  
      private void PropertyChangedEventHandler(object sender, PropertyChangedEventArgs e)
      {
        if (e != null &amp;&amp; !String.Equals(e.PropertyName, "IsChanged", StringComparison.Ordinal))
        {
          this.IsChanged = true;
        }
      }
  
      protected void OnPropertyChanged&lt;T&gt;(Expression&lt;Func&lt;T&gt;&gt; property)
      {
        MemberExpression me = property.Body as MemberExpression;
        if (me == null || me.Expression != property.Parameters[0]
              || me.Member.MemberType != MemberTypes.Property)
        {
          throw new InvalidOperationException(
              "Now tell me about the property");
        }
        var handler = PropertyChanged;
        if (handler != null) handler(this,
          new PropertyChangedEventArgs(me.Member.Name));
      }
  
      [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
      public bool IsChanged
      {
        get
        {
          lock (_notifyingObjectIsChangedSyncRoot)
          {
            return _notifyingObjectIsChanged;
          }
        }
  
        protected set
        {
          lock (_notifyingObjectIsChangedSyncRoot)
          {
            if (!Boolean.Equals(_notifyingObjectIsChanged, value))
            {
              _notifyingObjectIsChanged = value;
  
              if (IsDirtyChanged != null)
                IsDirtyChanged();
  
              this.OnPropertyChanged("IsChanged");
            }
          }
        }
      }
  
      private bool _notifyingObjectIsChanged;
      private readonly object _notifyingObjectIsChangedSyncRoot = new Object();
  
      public void AcceptChanges()
      {
        this.IsChanged = false;
      }
    }
  </code></pre>
  
  <p><strong>In the end</strong> I used a compare on the XML model from the XML serializer I already used. I did't 'need' instant change detection once a second (or so) would be enough. Now I check the XML model with the one I had since the last save.</p>