Skip to content

Instantly share code, notes, and snippets.

@ctolkien
Created March 19, 2013 23:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ctolkien/5201102 to your computer and use it in GitHub Desktop.
Save ctolkien/5201102 to your computer and use it in GitHub Desktop.
public override int SaveChanges()
{
//this goes through and updates the created on / modified on dates.
this.ChangeTracker.Entries<BaseModel>().ForEach(x =>
{
if (x.State == System.Data.EntityState.Added)
{
x.Entity.CreatedOn = DateTime.UtcNow;
}
x.Entity.ModifiedOn = DateTime.UtcNow;
});
return base.SaveChanges();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment