Reputation: 24903
Calling method SaveChanges
in DbContext
will call SaveChanges
in ObjectContext
with default save option SaveOptions.AcceptAllChangesAfterSave
.
So, all changes will be accpeted after save.
I want to control it in manual mode:
Now, 2 and 3 are united in one operation, so I can't to do some operations between 2 and 3. How can I divide it?
Upvotes: 2
Views: 729
Reputation: 24903
Based on Ivan Stoev's comment:
internal sealed class TestContext : DbContext
{
protected ObjectContext ObjectContext => ((IObjectContextAdapter)this).ObjectContext;
public override int SaveChanges()
{
//detect all changes in context
ChangeTracker.DetectChanges();
//write changes to database
var result = ObjectContext.SaveChanges(System.Data.Entity.Core.Objects.SaveOptions.None);
//do some actions with entities
DoStuff();
//accept all changes in entities
ObjectContext.AcceptAllChanges();
return result;
}
Upvotes: 2