Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework 4: ObjectContext event on successful save

Is there a good way to detect when the ObjectContext changes are actually committed?

SavingChanges occurs before going to the data store but I also need a way to know if those changes where actually committed.

Thanks in advance John

Update:

What I have is a code first DbContext. This is fed into dynamic data which as I discovered uses the DbContext's internal ObjectContext (to which I have access when casting to IObjectContextAdapter). The dbcontext's SaveChanges is not called, the objectcontext's SaveChanges is used instead. All I want to do is to be notified after the save is complete (i.e. event SavedChanges) so I can invalidate my cache.

like image 591
John Avatar asked Dec 31 '11 12:12

John


1 Answers

There is no build-in event to handle this but you can override SaveChanges method in your derived context and fire any custom event specific to your own context type after you call base.SaveChanges.

like image 89
Ladislav Mrnka Avatar answered Oct 04 '22 16:10

Ladislav Mrnka