I need to store a file in conjunction with a database entry. How can I override the Remove
method of the DbContext
so that both the entry and file are deleted?
Asked
Active
Viewed 71 times
3

M.Babcock
- 18,753
- 6
- 54
- 84
-
Couldn't you setup a trigger to do that for you? – M.Babcock Apr 09 '12 at 03:29
2 Answers
1
You can override the SaveChanges
method, as described here: Entity Framework 4.1 DbContext Override SaveChanges to Audit Property Change
Just add your own case for removals of specific entity types.
0
I would create new class extending of DbSet which pushes all other things through to the base but with remove it does your file change as well. This should work fine with DBcontext. It also means you can have your FileAndDbSet<T>
used for some entities and regular DbSet<T>
for the ones you dont have files with

undefined
- 33,537
- 22
- 129
- 198