Table of Contents

Class SoftDeleteExtensions

Namespace
MADE.Data.EFCore.Extensions
Assembly
MADE.Data.EFCore.dll

Defines a collection of extensions for supporting soft deletion of entities.

public static class SoftDeleteExtensions
Inheritance
SoftDeleteExtensions
Inherited Members

Methods

ApplySoftDeleteFilter(ModelBuilder)

Applies a global query filter to all entities implementing ISoftDeletable to exclude soft-deleted entities from queries by default.

public static void ApplySoftDeleteFilter(this ModelBuilder builder)

Parameters

builder ModelBuilder

The model builder to apply the filter to.

InterceptSoftDeletions(DbContext)

Intercepts save operations on the DbContext to automatically soft delete entities instead of hard deleting them.

Call this method in an override of the SaveChangesAsync method before calling the base implementation.

public static void InterceptSoftDeletions(this DbContext context)

Parameters

context DbContext

The DbContext.

Restore<T>(T)

Restores a soft-deleted entity by clearing the IsDeleted flag and the DeletedDate.

public static T Restore<T>(this T entity) where T : ISoftDeletable

Parameters

entity T

The entity to restore.

Returns

T

The restored entity.

Type Parameters

T

The type of entity to restore.

Exceptions

ArgumentNullException

Thrown if the entity is null.

SoftDelete<T>(T)

Soft deletes an entity by setting the IsDeleted flag to true and the DeletedDate to the current UTC time.

public static T SoftDelete<T>(this T entity) where T : ISoftDeletable

Parameters

entity T

The entity to soft delete.

Returns

T

The soft-deleted entity.

Type Parameters

T

The type of entity to soft delete.

Exceptions

ArgumentNullException

Thrown if the entity is null.