Part of DKNet.EfCore.Abstractions. Implement ISoftDeletableEntity when deletion records a flag, user and time instead of removing the object.
Use the console-project setup in the Quick Start, then replace Program.cs with this example.
using DKNet.EfCore.Abstractions.Entities;
using FluentResults;
var document = new Document();
document.Delete("alice");
Console.WriteLine(document.IsDeleted); // True
public sealed class Document : Entity, ISoftDeletableEntity
{
public bool IsDeleted { get; private set; }
public DateTimeOffset? DeletedOn { get; private set; }
public string? DeletedBy { get; private set; }
public IResultBase Delete(string user, DateTimeOffset? deletedOn = null)
{
IsDeleted = true;
DeletedBy = user;
DeletedOn = deletedOn ?? DateTimeOffset.UtcNow;
return Result.Ok();
}
}
The interface declares the fields and Delete contract; your method decides whether deletion succeeds. DeletedBy carries [MaxLength(250)] on the interface.
| Argument | Type | Default | Effect |
|---|---|---|---|
deletedOn |
DateTimeOffset? |
null |
Your implementation decides how to handle an omitted time. |
The domain decides whether deletion is allowed and records the deletion state. The host must supply filtering and save behavior; implementing this interface alone installs neither.