Entity Framework after save event

entity-framework entity-framework-6

Question

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?

1
2
5/30/2018 4:09:07 PM

Popular Answer

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();
    }

    ...
1
6/7/2017 5:25:07 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow