Efcore31.Auditable
1.0.1
dotnet add package Efcore31.Auditable --version 1.0.1
NuGet\Install-Package Efcore31.Auditable -Version 1.0.1
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="Efcore31.Auditable" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Efcore31.Auditable --version 1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Efcore31.Auditable, 1.0.1"
#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.
// Install Efcore31.Auditable as a Cake Addin
#addin nuget:?package=Efcore31.Auditable&version=1.0.1
// Install Efcore31.Auditable as a Cake Tool
#tool nuget:?package=Efcore31.Auditable&version=1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
First of all
Your DbContext needs to inherit from AuditableContext
public class ChinookContext : AuditableContext { ... }
Now you'll need to create the Audit table calling InitializeAudit(options) extention method
try
{
using(ChinookContext context = new ChinookContext())
{
// just like your DbContext configuration
context.InitializeAudit(o => o.UseSqlite(@"Data Source=chinook.db;"));
}
} catch(Exception ex) { ... }
Do that only one time. The Startup class is a great place for that.
Now let's play!
Into your DbContext add your DbSet and decorate it with [Audited] attribute
public class ChinookContext : AuditableContext
{
[Audited]
public DbSet<Artist> Artists { get; set; }
[Audited]
public DbSet<Album> Albums { get; set; }
}
If you prefer, you can decorate the entity class instead of the DbSet
That's it!
Now whenever you call the SaveChanges() or SaveChangesAsync() your decorated DbSets or entity classes will be audited.
using(ChinookContext context = new ChinookContext())
{
Artist artist = new Artist { Name = "OficinaG3" };
context.Add(artist);
context.SaveChanges();
artist.Name = "Oficina G3";
context.Update(artist);
Album album = new Album { ArtistId = artist.ArtistId, Title = "Depois da Guerra" };
context.Add(album);
context.SaveChanges();
context.Remove(album);
context.SaveChanges();
}
Result
Id | Tablename | Action | DateTime | KeyValues | OldValues | NewValues |
---|---|---|---|---|---|---|
1 | Artist | Added | 2020-01-13 19:33:44.4923153 | {"ArtistId":276} | {"Name":"OficinaG3"} | |
2 | Artist | Modified | 2020-01-13 19:33:44.711259 | {"ArtistId":276} | {"Name":"OficinaG3"} | {"Name":"Oficina G3"} |
3 | Album | Added | 2020-01-13 19:33:44.8758977 | {"AlbumId":348} | {"ArtistId":276,"Title":"Depois da Guerra"} | |
4 | Album | Deleted | 2020-01-13 19:33:45.0105142 | {"AlbumId":348} | {"ArtistId":276,"Title":"Depois da Guerra"} |
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
.NET Core | netcoreapp3.0 is compatible. netcoreapp3.1 was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETCoreApp 3.0
- Microsoft.EntityFrameworkCore (>= 3.1.0)
- Microsoft.EntityFrameworkCore.Relational (>= 3.1.0)
- Newtonsoft.Json (>= 12.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.