Many of the tables in my database need to have a \"DateCreated\" and \"DateModified\" column. I want to update these columns whenever SaveChanges()
is called.
The accepted solution here is better for above EF4 than the ObjectContext suggestion - we ran into issues with for instance the in memory db we used in the test context not working well with the above solution (getting Detached state for some modified entries in inheritance scenarios). This solution uses the DbContext native way of retrieving the tracked entities:
context.ChangeTracker.Entries()
.Where (t => t.State == EntityState.Modified)