using System.Collections.Generic;
using System.Data.Entity;
using Z.EntityFramework.Classic;
public class EntityContext : DbContext
public EntityContext() : base(FiddleHelper.GetConnectionStringSqlServer())
this.Configuration.Audit.AutoSaveAction = (context,auditing) => {
using (System.IO.StreamWriter file =
new System.IO.StreamWriter(@"Log.txt"))
foreach(var entry in auditing.EntriesXml)
file.WriteLine("EntitySetName: " + entry.EntitySetName);
file.WriteLine("EntityTypeName: " + entry.EntityTypeName);
file.WriteLine("State: " + entry.State);
file.WriteLine("StateName: " + entry.StateName);
file.WriteLine("CreatedBy: " + entry.CreatedBy);
file.WriteLine("CreatedDate: " + entry.CreatedDate);
file.WriteLine("XmlProperties: ");
file.WriteLine(entry.XmlProperties);
this.Configuration.Audit.IsEnabled = true;
public DbSet<Customer> Customers { get; set; }
public static void Main()
using (var context = new EntityContext())
context.Customers.Add(new Customer() { Name = "Customer_A", Description = "Description" });
context.Customers.Add(new Customer() { Name = "Customer_B", Description = "Description" });
context.Customers.Add(new Customer() { Name = "Customer_C", Description = "Description" });
string[] lines = System.IO.File.ReadAllLines(@"Log.txt");
foreach (string line in lines)
public int CustomerID { get; set; }
public string Name { get; set; }
public string Description { get; set; }