Audentity 1.0.1
dotnet add package Audentity --version 1.0.1
NuGet\Install-Package Audentity -Version 1.0.1
<PackageReference Include="Audentity" Version="1.0.1" />
paket add Audentity --version 1.0.1
#r "nuget: Audentity, 1.0.1"
// Install Audentity as a Cake Addin
#addin nuget:?package=Audentity&version=1.0.1
// Install Audentity as a Cake Tool
#tool nuget:?package=Audentity&version=1.0.1
Audentity
Auditing library for Entity Framework
Usage
Collect traces by catching the state of the Microsoft.EntityFrameworkCore.ChangeTracking.ChangeTracker
before saving changes. That can be done simply by overriding the SaveChanges()
& SaveChangesAsync(CancellationToken)
methods in your Microsoft.EntityFrameworkCore.DbContext
implementation.
public class MyDbContext : DbContext
{
public override async Task<int> SaveChangesAsync(CancellationToken cancellationToken = new())
{
ImmutableList<EntityTrace> traces = ChangeTracker.Entries()
.Select(EntityTrace.FromEntry)
.ToList();
int result = await base.SaveChangesAsync(cancellationToken);
// Process traces...
return result;
}
}
Shadow Entries
If you have many-to-many relationships in your database model, Entity Framework will generate a shadow entity that represents a reference between two entities - unless you have defined such an entity yourself.
public class Project
{
public Guid Id { get; set; }
public IEnumerable<User> Users { get; set; }
}
public class User
{
public Guid Id { get; set; }
public IEnumerable<Project> Projects { get; set; }
}
// Shadow entity generated by Entity Framework:
public class ProjectUser
{
public Guid ProjectId { get; set; }
public Guid UserId { get; set; }
}
Those entities, even if they are not defined in the code itself, will still end up in our trace collection. To exclude them from traces, you can filter all entries by their CLR type before collecting traces.
ChangeTracker.Entries()
.Where(e => e.Metadata.ClrType != typeof(Dictionary<string, object>))
.Select(EntityTrace.FromEntry);
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net8.0
- Microsoft.EntityFrameworkCore (>= 8.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.