title: Entity Framework 4 Change Audit
body: <p>I have a web application using EF4. I am somewhat new to EF and now trying to implement change Audit.I tried to do this by trapping the SavingChanges event of the Context Class as below</p>
  
  <pre><code>partial void OnContextCreated()
          {
              this.SavingChanges += new EventHandler(TicketContainer_SavingChanges);
  
          }
  </code></pre>
  
  <p>So the event handler accesses the changed records by the following</p>
  
  <pre><code>this.ObjectStateManager.GetObjectStateEntries(
               EntityState.Added | EntityState.Modified);
  </code></pre>
  
  <p>This works fine and I am creating column level audit for selected tables. Every table/entity has an ID field which is an identifier with columnName="ID". So in my audit routine I simply accesses data from column with name "Id" to get the ID of audited record.</p>
  
  <p>The problem I face is during insert . The new record has no ID yet as it is an identity column in the database and is always 0.</p>
  
  <p>One solution I can think of is using GUID for all Ids.But is there a way to implement this using standard int32 Identity Ids?</p>
  
  <p>thanks</p>