title: Extend Entity Framework Save on a single Entity Type
body: <p>I have a rather large save routine that updates hundreds of items using the Entity Framework and then saves the whole lot in one go.</p>
  
  
  
  <pre class="lang-cs prettyprint-override"><code>using (var dc = new EntityLayer.Entities())
  {
      dc.Entity1.Prop1 = 1;
      dc.Entity1.Prop2 = 2;
      dc.Entity2.Prop1 = 1;
      dc.Entity2.Prop2 = 2; // Audit item
      dc.Entity2.Prop3 = 3; // Audit item
      dc.Entity3.Prop1 = 1;
      ...
      dc.SaveChanges();
  }
  </code></pre>
  
  <p>What I would love to be able to do is somehow either extend the Save for an individual Entity or pick up on this change and kick off another method.</p>
  
  <p>The main purpose of this is to hook into our Audit system, which only audits some key items, (so for example only Entity2.Prop2 and Entity2.Prop3 in the simplified version above) but would also possibly kick off some other routines, creating tasks etc, but the crux is - can it be done?</p>
  
  <p>Basically I'm aiming to remove the extra audit line we have to put in for specific types as below:</p>
  
  
  
  <pre class="lang-cs prettyprint-override"><code>using (var dc = new EntityLayer.Entities())
  {
      dc.Entity1.Prop1 = 1;
      dc.Entity1.Prop2 = 2;
      dc.Entity2.Prop1 = 1;
      dc.Entity2.Prop2 = 2;
      dc.Audit.CreateObject() { Type = "Entity2", Change = "Prop2", From = oldVal, To = 2}
      dc.Entity2.Prop3 = 3;
      dc.Audit.CreateObject() { Type = "Entity2", Change = "Prop3", From = oldVal, To = 3}
      ...
      dc.SaveChanges();
  }
  </code></pre>