Overriding deletion of entities

I need to save a file along with a database record. How can I override the method Remove

DbContext

to delete both the entry and the file?

+3


source to share


2 answers


You can override the method SaveChanges

as described here: Entity Framework 4.1 DbContext override SaveChanges to change audit properties



Just add your own case to remove specific types of objects.

+1


source


I would create a new class that extends DbSet that pushes all other things to the base, but with deletion, it also modifies your file. This should work fine with DBcontext. This also means that you can use FileAndDbSet<T>

for some objects and normal DbSet<T>

for those that do not have files with



0


source







All Articles