using System.Collections.Generic;
using System.Data.Entity;
using Z.EntityFramework.Classic;
public class EntityContext : DbContext
public EntityContext() : base(FiddleHelper.GetConnectionStringSqlServer())
this.Configuration.Audit.SoftDeleted(x => x.GetType() == typeof(Customer) && ((Customer)x).IsDeleted);
this.Configuration.Audit.AutoSaveSet = this.XmlAuditEntries;
this.Configuration.Audit.IsEnabled = true;
public DbSet<Customer> Customers { get; set; }
public DbSet<XmlAuditEntry> XmlAuditEntries { get; set; }
public static void Main()
using (var context = new EntityContext())
context.Configuration.Audit.IsEnabled = false;
context.Customers.Add(new Customer() { Name = "Customer_A", Description = "Description" });
using (var context = new EntityContext())
context.Customers.ToList().ForEach(x => x.IsDeleted = true);
FiddleHelper.WriteTable("Entity Framework - Audit Trail", context.XmlAuditEntries.ToList());
public int CustomerID { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public bool IsDeleted { get; set; }