using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using Microsoft.Data.SqlClient;
using Z.EntityFramework.Plus;
public static void Main()
using (var context = new EntityContext())
context.Database.EnsureCreated();
AuditManager.DefaultConfiguration
.AuditEntryFactory = args =>
new AuditEntry() { CreatedDate = DateTime.Now.AddHours(-5) };
using (var context = new EntityContext())
context.Customers.Add(new Customer() { Name = "Customer_C", Description = "Description", IsActive = false});
audit.Configuration.AuditEntryFactory = args =>
new AuditEntry() { CreatedBy = "ZZZ Projects"};
context.SaveChanges(audit);
var entries = audit.Entries;
FiddleHelper.WriteTable("All Entry",entries);
foreach(var entry in entries)
FiddleHelper.WriteTable("Properties for One Entry",entry.Properties);
public class EntityContext : DbContext
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
optionsBuilder.UseSqlServer(new SqlConnection(FiddleHelper.GetConnectionStringSqlServer()));
base.OnConfiguring(optionsBuilder);
public DbSet<Customer> Customers { get; set; }
public int CustomerID { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public Boolean IsActive { get; set; }