using System.Collections.Generic;
using System.Data.Entity;
using Z.EntityFramework.Classic;
public class EntityContext : DbContext
public EntityContext() : base(FiddleHelper.GetConnectionStringSqlServer())
this.Configuration.Audit.ExcludeProperty<Customer>(x => x.Description);
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.Customers.Add(new Customer() { Name = "Customer_A", Description = "Description" });
var auditEntries = context.XmlAuditEntries.ToAuditEntries();
FiddleHelper.WriteTable("1 - Entity Framework - All Property Exclude (Key properties are never excluded);", auditEntries.SelectMany(x => x.Properties));
using (var context = new EntityContext())
context.Customers.Add(new Customer() { Name = "Customer_B", Description = "Description" });
context.Configuration.Audit.IncludeProperty<Customer>(x => x.Description);
var auditEntries = context.XmlAuditEntries.ToAuditEntries();
FiddleHelper.WriteTable("2 - Entity Framework - context.Configuration.Audit.IncludeProperty<Customer>(x => x.Description);", auditEntries.SelectMany(x => x.Properties));
public int CustomerID { get; set; }
public string Name { get; set; }
public string Description { get; set; }