AuditLog.EntityFrameworkCore.SoftDelete 0.4.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package AuditLog.EntityFrameworkCore.SoftDelete --version 0.4.2
                    
NuGet\Install-Package AuditLog.EntityFrameworkCore.SoftDelete -Version 0.4.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AuditLog.EntityFrameworkCore.SoftDelete" Version="0.4.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AuditLog.EntityFrameworkCore.SoftDelete" Version="0.4.2" />
                    
Directory.Packages.props
<PackageReference Include="AuditLog.EntityFrameworkCore.SoftDelete" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add AuditLog.EntityFrameworkCore.SoftDelete --version 0.4.2
                    
#r "nuget: AuditLog.EntityFrameworkCore.SoftDelete, 0.4.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package AuditLog.EntityFrameworkCore.SoftDelete@0.4.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=AuditLog.EntityFrameworkCore.SoftDelete&version=0.4.2
                    
Install as a Cake Addin
#tool nuget:?package=AuditLog.EntityFrameworkCore.SoftDelete&version=0.4.2
                    
Install as a Cake Tool

AuditLog

Publish to NuGet

Biblioteca de auditoria automática para EF Core com Source Generators Roslyn.

Pacotes

Pacote Descrição
AuditLog.Abstractions Contratos: AuditConfigurator<T>, IAuditDescriptor, builders
AuditLog.EntityFrameworkCore Integração EF Core: AuditSaveInterceptor, extensions
AuditLog.Generator Source generator — gera *AuditLog, maps, descriptors
AuditLog.EntityFrameworkCore.SoftDelete Runtime: interfaces, interceptor, query filters para soft delete
AuditLog.Generator.SoftDelete Source generator — gera handlers tipados de cascade/restrict/set-null

AuditLog — Auditoria de Entidades

1. Defina um configurador

[GenerateAuditLog]
public sealed class PacienteAuditConfigurator : AuditConfigurator<Paciente>
{
    public PacienteAuditConfigurator()
    {
        For(x => x.Id).Key();
        For(x => x.Nome).HasMaxLength(200).IsRequired();
        For(x => x.Cpf).Sensitive().HasMaxLength(11);
        For(x => x.DataAtualizacao).Ignore();
    }
}

2. Adicione o interceptor no DbContext

public class AppDbContext : DbContext
{
    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        optionsBuilder.AddInterceptors(new AuditSaveInterceptor());
    }
}

3. O generator produz automaticamente

  • PacienteAuditLog — tabela de auditoria com snapshot dos dados
  • PacienteAuditLogDescriptor — mapeia Paciente → PacienteAuditLog
  • PacienteAuditLogEntityMap — EF Core configuration (column types, max length)
  • ServiceCollectionExtensions.AddGeneratedAuditLogs() — DI registration

SoftDelete — Exclusão Lógica

Dois pacotes complementares:

Package Função
AuditLog.EntityFrameworkCore.SoftDelete Runtime: interceptor, interfaces, query filters
AuditLog.Generator.SoftDelete Source generator (opcional): gera handlers com tipagem forte

Instalação

<ItemGroup>
  <PackageReference Include="AuditLog.EntityFrameworkCore.SoftDelete" Version="1.0.0" />
  <PackageReference Include="AuditLog.Generator.SoftDelete" Version="1.0.0" />
</ItemGroup>

1. Implemente ISoftDeleteEntity nas entidades

public class Paciente : ISoftDeleteEntity
{
    public Guid Id { get; set; }
    public string Nome { get; set; }

    // Obrigatório para soft delete
    public bool IsDeleted { get; set; }
    public DateTime? DeletedAt { get; set; }

    // Relacionamentos (Fluent API configurada no DbContext)
    public List<Notificacao> Notificacoes { get; set; } = [];
}

2. Marque o DbContext com [GenerateSoftDelete]

using AuditLog.EntityFrameworkCore.SoftDelete;

[GenerateSoftDelete]
public class AppDbContext : DbContext
{
    public DbSet<Paciente> Pacientes { get; set; }
    public DbSet<Notificacao> Notificacoes { get; set; }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Paciente>(e =>
        {
            e.HasMany(x => x.Notificacoes)
                .WithOne(x => x.Paciente)
                .HasForeignKey(x => x.PacienteId)
                .OnDelete(DeleteBehavior.Cascade);
        });

        modelBuilder.ApplySoftDeleteQueryFilter();
    }
}

3. Registre na DI

// Com o source generator (handlers tipados)
var registry = new SoftDeleteHandlerRegistry();
registry.AddGeneratedSoftDeleteHandlers();
services.AddSoftDelete(registry);

// Ou sem o generator (fallback via reflection)
services.AddSoftDelete();

4. Use normalmente

db.Pacientes.Remove(paciente);
await db.SaveChangesAsync();
// → IsDeleted = true, DeletedAt = now
// → Cascade: Notificacoes também são marcadas como deletadas
// → Query filter global: db.Pacientes retorna apenas não-deletados

Comportamentos por FK

OnDelete() Efeito
Cascade Dependentes são soft-deletados recursivamente
Restrict Lança RestrictDeleteViolationException se houver dependentes
SetNull FK dos dependentes é setada como null

Convenções (quando OnDelete não é especificado)

Navigation Comportamento
Collection (List<T>) Cascade
Reference (T) Restrict
FK nullable (Guid?) SetNull

Consultas

// Query filter automático — só não-deletados
db.Pacientes.ToList();

// Incluir deletados
db.Pacientes.IgnoreQueryFilters().ToList();

Suporte a herança indireta de IEntityTypeConfiguration<T>

O gerador detecta entity maps que implementam IEntityTypeConfiguration<T> através de toda a cadeia de herança, incluindo casos como AuditEntityMap<T>IContextEntityMap<T>IEntityTypeConfiguration<T>. Isso funciona tanto com ApplyConfiguration(new ConcreteEntityMap()) quanto com ApplyConfigurationsFromAssembly().

Descoberta de entidades sem DbSet<T>

O gerador descobre entidades mesmo quando o DbContext não possui propriedades DbSet<T>, desde que as entidades sejam registradas via modelBuilder.Entity<T>() no OnModelCreating ou via ApplyConfiguration/ApplyConfigurationsFromAssembly com entity maps que implementam IEntityTypeConfiguration<T>.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.4.4 0 7/22/2026
0.4.3 0 7/22/2026
0.4.2 0 7/22/2026
0.4.1 0 7/22/2026
0.4.0 0 7/22/2026
0.3.3 43 7/20/2026
0.3.1 62 7/20/2026
0.3.0 70 7/20/2026
0.2.0 112 6/30/2026