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.
public class MyContext : DbContext
{
//...
public override int SaveChanges()
{
foreach (var dbEntityEntry in ChangeTracker.Entries())
{
dbEntityEntry.Entity.UpdateDates();
}
return base.SaveChanges();
}
}