Reputation: 111
When any record deletes from some table (let us call it STORAGE_INFO) additional data from disk must be deleted.Could anyone provide a sample (if it possible yet) how to specify own DELETE action? Something like this:
DBSet<STORAGE_INFFO>.ONDELETE+= CUSTOM_FUNCTION
CUSTOM_FUNCTION()
{
BASE.DELETE();
DELETE_DISK_CONTENT();
}
Upvotes: 2
Views: 139
Reputation: 64923
Probably you're looking for the ObjectContext.SavingChanges
event
If you iterate the result of calling the context.ObjectStateManager.GetObjectStateEntries(EntityState.Deleted)
method using the whole overload, you'll be able to detect which entities were deleted when the ObjectContext
saved some changes.
Check the sample code in the MSDN article (it's a good sample of how to achieve your goal!):
this is pretty.But where can I find this event in DBContext class?
Upcast the DbContext
to IObjectContextAdapter
:
((IObjectContextAdapter)dbContext).ObjectContext.SavingChanges += ...
Upvotes: 2