I have something like this:
public override int SaveChanges() { foreach (var changeLog in this.ChangeTracker.Entries() .Where(p => p.State == EntityState.Added || p.State == EntityState.Deleted || p.State == EntityState.Modified) .SelectMany(entity => AuditRecords(entity))) { this.ChangeLogs.Add(changeLog); } return base.SaveChanges(); }
But, of course, checked change logs will not contain the primary key value for the object when adding an EntityState (before SaveChanges). How can I get the primary key value for audit change?
Richard
I would save references to objects in List<T>(or an array or other such structure), and then do a call to the base implementation SaveChanges.
List<T>
SaveChanges
, ( , , ), , .
, , Entity Entity ( , ChangeLogs); . , , .
ChangeLogs
GUID , .