【发布时间】:2014-07-20 16:42:45
【问题描述】:
我的实体有以下更新通用方法:
public void Update < T > (T entity) where T: class {
DbEntityEntry dbEntityEntry = DbContext.Entry(entity);
if (dbEntityEntry.State == System.Data.Entity.EntityState.Detached) {
DbContext.Set < T > ().Attach(entity);
}
dbEntityEntry.State = System.Data.Entity.EntityState.Modified;
}
SaveChanges()后数据库中的数据更新成功。
现在我需要在SaveChanges() 之前实施和审核日志,但我注意到CurrentValues 等于OriginalValues:
// For updates, we only want to capture the columns that actually changed
if (!object.Equals(dbEntry.OriginalValues.GetValue<object>(propertyName), dbEntry.CurrentValues.GetValue<object>(propertyName))){
//here I add a new Audit Log entity
}
关于如何解决这个问题的任何线索?或者在 Entity Framework 6 中有更好的方法吗?
【问题讨论】:
标签: entity-framework entity-framework-4.1 audit-trail