Efcore: Soft Delete

Created on 9 Dec 2015  路  9Comments  路  Source: dotnet/efcore

Hello.

Any suggestions on how to implement a soft delete at Entity Framework 7 ?

Any help is much appreciated.

Regards.

type-enhancement

Most helpful comment

Note to implementer: remember to make cascade delete (of tracked entities) work.

All 9 comments

We're putting this one on the backlog as a feature we would like to have at some point.

In the meantime, you probably could do this by overriding some of the low level components... but that is going to be fairly complex to do. If you decide to try... then you will probably make things less painful if you have your soft delete flag mapped as a shadow state property. For SaveChanges, you could look at a custom implementation of ICommandBatchPreparer.BatchCommands to generate updates rather than deletes for state entries that are marked as deleted.

cc @anpete in case he can give you a pointer of where to look for query.

Enabled in b1379b10f

I think we definitely need an opt-out operator like: .NotFiltered()

@anpete - Is this issue fully resolved? If yes then we should close the issue and set the milestone.

cc: @divega

Unless we want to track a specific high-level Soft Delete feature.

I think we do want to track that feature. Specifically, I should be able to delete objects normally in my graph or with .Remove, and then have it automatically soft delete those entities.

Agreed. Query filters only solves a part of what we need.

Note to implementer: remember to make cascade delete (of tracked entities) work.

Was this page helpful?
0 / 5 - 0 ratings