FrontLook.IAutoHistory
8.24.421.8
dotnet add package FrontLook.IAutoHistory --version 8.24.421.8
NuGet\Install-Package FrontLook.IAutoHistory -Version 8.24.421.8
<PackageReference Include="FrontLook.IAutoHistory" Version="8.24.421.8" />
paket add FrontLook.IAutoHistory --version 8.24.421.8
#r "nuget: FrontLook.IAutoHistory, 8.24.421.8"
// Install FrontLook.IAutoHistory as a Cake Addin #addin nuget:?package=FrontLook.IAutoHistory&version=8.24.421.8 // Install FrontLook.IAutoHistory as a Cake Tool #tool nuget:?package=FrontLook.IAutoHistory&version=8.24.421.8
AutoHistory
A plugin for Microsoft.EntityFrameworkCore to support automatically recording data changes history.
How to use
AutoHistory
will recording all the data changing history in one Table
named AutoHistories
, this table will recording data
UPDATE
, DELETE
history.
- Install AutoHistory Package
Run the following command in the Package Manager Console
to install Microsoft.EntityFrameworkCore.AutoHistory
PM> Install-Package Microsoft.EntityFrameworkCore.AutoHistory
- Enable AutoHistory
public class BloggingContext : DbContext
{
public BloggingContext(DbContextOptions<BloggingContext> options)
: base(options)
{ }
public DbSet<Blog> Blogs { get; set; }
public DbSet<Post> Posts { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
// enable auto history functionality.
modelBuilder.EnableAutoHistory();
}
}
- Ensure AutoHistory in DbContext. This must be called before bloggingContext.SaveChanges() or bloggingContext.SaveChangesAsync().
bloggingContext.EnsureAutoHistory()
Use Custom AutoHistory Entity
You can use a custom auto history entity by extending the Microsoft.EntityFrameworkCore.AutoHistory class.
class CustomAutoHistory : AutoHistory
{
public String CustomField { get; set; }
}
Then register it in the db context like follows:
modelBuilder.EnableAutoHistory<CustomAutoHistory>(o => { });
Then provide a custom history entity creating factory when calling EnsureAutoHistory. The example shows using the
factory directly, but you should use a service here that fills out your history extended properties(The properties inherited from AutoHistory
will be set by the framework automatically).
db.EnsureAutoHistory(() => new CustomAutoHistory()
{
CustomField = "CustomValue"
});
Integrate AutoHistory into other Package
Microsoft.EntityFrameworkCore.UnitOfWork had integrated this package.
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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
-
net8.0
- Microsoft.EntityFrameworkCore (>= 8.0.4)
- Microsoft.EntityFrameworkCore.Relational (>= 8.0.4)
- Newtonsoft.Json (>= 13.0.3)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on FrontLook.IAutoHistory:
Package | Downloads |
---|---|
FrontLookCoreLibraryAssembly.Hosting.DbContext
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|