Skip to content

Instantly share code, notes, and snippets.

@Krizzzn
Created September 28, 2011 20:46
Show Gist options
  • Save Krizzzn/1249217 to your computer and use it in GitHub Desktop.
Save Krizzzn/1249217 to your computer and use it in GitHub Desktop.
C#: EF Save Event Handler
public override int SaveChanges(SaveOptions options)
{
foreach (ObjectStateEntry entry in
ObjectStateManager.GetObjectStateEntries(
EntityState.Added | EntityState.Modified))
{
// Validate the objects in the Added and Modified state
// if the validation fails throw an exeption.
}
return base.SaveChanges(options);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment