public void ProcessEntry(DbEntityEntry entry) { var historyEntry = DbChangeHistoryEntry.FromDbEntityEntry(entry); if (historyEntry != null) { if (_entries == null) { _entries = new List <DbChangeHistoryEntry>(); } _entries.Add(historyEntry); } }
public static DbChangeHistoryEntry FromDbEntityEntry(DbEntityEntry entry) { if (entry.State != EntityState.Added && entry.State != EntityState.Modified && entry.State != EntityState.Deleted) { return(null); } if (!(entry.Entity is IChangeHistoryEntity)) { return(null); } var result = new DbChangeHistoryEntry { _entry = entry, _entity = entry.Entity, _state = entry.State, _properties = new Dictionary <string, DbChangeHistoryEntryProperty>() }; var propertyNames = entry.State == EntityState.Deleted ? entry.OriginalValues.PropertyNames : entry.CurrentValues.PropertyNames; foreach (string propName in propertyNames) { var entryProperty = entry.Property(propName); var historyProperty = new DbChangeHistoryEntryProperty { Name = propName }; if (entry.State != EntityState.Added) { historyProperty.OldValue = entryProperty.OriginalValue; } if (entry.State != EntityState.Deleted) { historyProperty.NewValue = entryProperty.CurrentValue; } result._properties.Add(propName, historyProperty); } return(result); }