Code Monkey home page Code Monkey logo

efcore.softdeleteservices's Introduction

EfCore.SoftDeleteServices

This library to provide simple soft delete and cascade soft delete in EF Core. It provides:

  • Useful methods: The features in this library are:
    • Set the SoftDeleted flag on an entity class, with checks.
    • Provides a secure query to find all the Soft Deleted entities for a specific entity class.
    • Reset the SoftDeleted flag on an entity class, which checks.
    • Hard delete (i.e. call EF Core Remove method) a entity class, but only if it is already Soft Deleted.
      NOTE: Methods can work with entity instance, or found via primary keys. Also has sync and async versions of all methods.
  • Cascade Soft Delete: This library has a service that can mimic the database cascade delete, but Soft Deleting the entities. For instance, Cascade Soft Deleting a Company could also soft delete dependent relationships (see image below).
  • Keeps your data secure: This library can handle Query Filters that contain multiple parts to the filter, e.g. Soft Delete with a multi-tenant filter. It builds queries that will replace the other filters so that your data stays secure.
  • Fully configurable: It works with your properties and interfaces. The only rule it has is your Soft Delete property must provide true/false value (normally a 'bool', but could be part of enum status, etc.), or for the cascade delete it must provide a byte value.
  • DI-friendly: This library is designed to work with dependency injection (DI) and contains a method which will scan for your Soft Delete configuration files and set up all the services you need to use this library.

Here is an image to show the difference between normal (single) soft delete and cascade soft delete.

Two types of soft delete

The cascade soft delete is pretty clever, and can handle multi-level soft deletes - see this section from my article EF Core In depth - Soft deleting data with Global Query Filters.

MIT License.

Documentation

Documentation can be found in the Repo's Wiki.

Limitations

  • When loading via keys it assumes the primary key property(s) are properties.
  • The navigational links have to be properties.

All of these limitations could be removed, but it takes time to implement and check.

Terms

  • Hard delete is when you delete a row in the database, via the EF Core Remove method. A hard delete removes the row from the database and may effect other entities/rows.
  • Single soft delete mimics a one row, hard delete. The entity/row is still in the database, but won't show up in EF Core query. But you can un-soft delete, referred to as a soft delete reset, and the makes the entity visible in an EF Core query.
  • Cascade soft delete mimics the hard delete's cascade approach and will soft delete any dependant relationships (the EF Core DeleteBehavior has an effect on what happens).
  • Soft delete covers both Single soft delete and Cascade soft delete

efcore.softdeleteservices's People

Contributors

jonpsmith avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.