Skip to content

Soft Delete #4025

Open

Description

Hello.

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

Any help is much appreciated.

Regards.

Activity

  1. added this to the Backlog milestone on Dec 22, 2015
  2. rowanmiller commented on Dec 22, 2015

    @rowanmiller
    Contributor

    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.

  3. anpete commented on May 8, 2017

    @anpete
    Contributor

    Enabled in b1379b1

  4. seriouz commented on May 9, 2017

    @seriouz

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

  5. smitpatel commented on May 9, 2017

    @smitpatel
    Contributor
  6. removed this from the Backlog milestone on May 9, 2017
  7. smitpatel commented on May 9, 2017

    @smitpatel
    Contributor

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

    cc: @divega

  8. anpete commented on May 9, 2017

    @anpete
    Contributor

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

  9. ajcvickers commented on May 9, 2017

    @ajcvickers
    Contributor

    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.

  10. divega commented on May 9, 2017

    @divega
    Contributor

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

  11. added this to the Backlog milestone on May 12, 2017
  12. ajcvickers commented on Mar 12, 2018

    @ajcvickers
    Contributor

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

  13. Geestarraw commented on Oct 15, 2023

    @Geestarraw
  14. roji commented on Oct 16, 2023

    @roji
  15. qsdfplkj commented on Oct 21, 2023

    @qsdfplkj

    To me soft deletes don't make sense. On a database level: Any unique constraint will break. What about a foreign key that has been soft deleted? Do we need cascading soft deletes? You could build an entire shadow database with soft deleted entities. To me soft deletes should be related to business logic, e.g. add an start and end date to a subscription. Soft delete will only work on database that do not have any constraints but then the problem is just moved to the point of where we need to read the data.

    Maybe temporal tables can be used for soft deletes.

  16. seriouz commented on Oct 21, 2023

    @seriouz

    Yes soft deletes should respect cascade delete. Sure you can implement it easy by youself with thousands of possibilities. But i imagine an EF Core Soft Delete like a ready-to-go solution - where i (as a dev) have not to know how its working behind the scenes and i don't have to touch the queries (apart from when i must read/recover deleted data).

  17. added theissue type on Jun 15, 2025
  18. marked End-to-end soft delete #19695 as a duplicate of this issue on Jun 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions