A plugin for Microsoft.EntityFrameworkCore to support automatically recording data changes history.
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
bloggingContext.EnsureAutoHistory()
Microsoft.EntityFrameworkCore.UnitOfWork had intergrated this package.