Is there a SaveChanges
event that fires after changes are saved, but before the change tracker is updated?
I am using EF 6.
I need to perform a task whenever the status changes on a certain entity.
I have overridden SaveChanges
to set this up. I can use ChangeTracker
to tell what changes. When it's the correct entity with the correct change I fire of my code.
After the base SaveChanges
is called, ChangeTracker
no longer shows the entity as modified, so I need to do my task just before I save. However, there is a chance that SaveChanges
will fail and I should not have done my task.
How can I hook into the ChangeTracker
after the save, but before the model and ChangeTracker
is updated?
Can you override the save changes method?
//you will use a different dbcontext name than faroutEntities5
public partial class faroutEntities5 : DbContext
{
public faroutEntities5()
: base("name=faroutEntities5")
{
}
public override int SaveChanges()
{
ChangeTracker.Entries()....
return base.SaveChanges();
}
...