title: Update an entity property when another property changes (after entity is initialized)
body: <p>I am using Entity Framework and Code First approach in a WPF MVVM application backed by a SQL CE database. I am trying to design a model class that can simply update one of its property values in response to another one of its property values changing. Basically, I am looking for a way to define a poco that is "self-tracking" after the instance is initialized by EF. If the answer involves abandoning Code First, then maybe that is the only viable route (not sure). A basic example:</p>
  
  <pre class="lang-cs prettyprint-override"><code>class ThingModel
  {
      public int Id { get; set; }
  
      public bool OutsideDbNeedsUpdate { get; set; }
  
      private string _foo;
  
      public string Foo
      {
          get { return _foo; }
  
          set
          {
              if (_foo != value)
              {
                  _foo = value;
  
                  OutsideDbNeedsUpdate = true;
              }
          }
      }
  }
  </code></pre>
  
  <p>However, the problem with the above is that whenever DbContext is initializing an instance at runtime and setting the fields, my class is prematurely setting the dependent field in response. In other words, I am searching for a simple pattern that would allow my poco class to ONLY do this special change tracking after EF has finished initializing the fields on an instance.</p>
  
  <p>I realize I could do something like the solution <a href="https://stackoverflow.com/questions/3131347/entity-framework-check-if-there-are-changes-to-be-saved">here</a>
  but my business case requires that this special change tracking be decoupled from the EF change tracking, in other words, I require the ability to SaveChanges regardless of the state of the HasChanges property above. This is because I would like to be able to periodically check the HasChanges property on my entities and in turn update dependent values in an outside database (not the same one backing the EF DbContext) and many changes/saves may happen to the EF DB between pushes to the outside DB. Hence the reason I was hoping to just persist the flag with the record in my DB and reset it to false when the periodic update to the outside DB occurs.</p>