using System.Data.Entity;
using Z.EntityFramework.Plus;
public static void Main()
using (var context = new EFPlusContext())
var person = new Person { Name = "P1", IsSoftDeleted = true };
context.People.Add(person);
person.IsSoftDeleted = false;
audit.Configuration.SoftAdded<Person>(x => {
var entry = context.GetObjectContext().ObjectStateManager.GetObjectStateEntry(x);
var IsSoftDeletedOrdinal = entry.CurrentValues.GetOrdinal("IsSoftDeleted");
return entry.CurrentValues.GetValue(IsSoftDeletedOrdinal) != entry.OriginalValues.GetValue(IsSoftDeletedOrdinal);
audit.Configuration.SoftDeleted<Person>(x => {
var entry = context.GetObjectContext().ObjectStateManager.GetObjectStateEntry(x);
var IsSoftDeletedOrdinal = entry.CurrentValues.GetOrdinal("IsSoftDeleted");
return entry.CurrentValues.GetValue(IsSoftDeletedOrdinal) != entry.OriginalValues.GetValue(IsSoftDeletedOrdinal);
audit.CreatedBy = "Someone";
context.SaveChanges(audit);
var auditEntry = context.AuditEntries.Single();
Console.WriteLine(auditEntry.StateName);
class EFPlusContext : DbContext
public EFPlusContext() : base(FiddleHelper.GetConnectionStringSqlServer())
AuditManager.DefaultConfiguration.AutoSavePreAction = (context, audit) =>
(context as EFPlusContext).AuditEntries.AddRange(audit.Entries);
public DbSet<Person> People { get; set; }
public DbSet<AuditEntry> AuditEntries { get; set; }
public DbSet<AuditEntryProperty> AuditEntryProperties { get; set; }
public int Id { get; set; }
public string Name { get; set; }
public bool IsSoftDeleted { get; set; }