I have an issue where I want to override SaveChanges() as I need to check some values being saved to the database and change them before they are saved.
I know I can override SaveChanges() in the DBContext:
var changeSet = ChangeTracker.Entries<Page>();
if (changeSet != null)
{
foreach (var entry in changeSet)
{
switch (entry.State)
{
case System.Data.EntityState.Added:
if (((Page)entry.Entity).Parent_PageID == -1)
((Page)entry.Entity).Parent_PageID = null;
break;
}
}
}
but this will get messy very quickly if I need to do this on multiple models.
How can I do this per model?