title: DbContext ChangeTracker: Id of Added Entity for Auditing
body: <p>I have something like this:</p>
  
  <pre><code>public override int SaveChanges()
  {
      foreach (var changeLog in this.ChangeTracker.Entries()
          .Where(p =&gt; p.State == EntityState.Added ||
                 p.State == EntityState.Deleted ||
                 p.State == EntityState.Modified)
          .SelectMany(entity =&gt; AuditRecords(entity)))
      {
          this.ChangeLogs.Add(changeLog);
      }
  
      return base.SaveChanges();
  }
  </code></pre>
  
  <p>But, of course, audited change logs will not contain the primary key value of the entity when the EntityState is Added (until after SaveChanges). How can I obtain the primary key value for change auditing purposes?</p>
  
  <p>Richard</p>