目前,我正在寻找一种在 [context].SubmitChanges() 中查找实体旧值的方法。
据我所知,只有新值出现。我真的需要查询数据库来获取实体的旧值吗?
GertArnold的解决方案:
public override void SubmitChanges(System.Data.Linq.ConflictMode failureMode)
{
// Get the changeset
ChangeSet changeSet = this.GetChangeSet();
// Put the updated objects into a IEnumerable
IEnumerable<object> updatedEntities = changeSet.Updates;
foreach (var entity in updatedEntities.Where(entity => AuditTypes.Contains(entity.GetType())))
{
var old = this.GetTable(entity.GetType()).GetModifiedMembers(entity);
// Do something with the old values
}
// Save the changes
base.SubmitChanges(failureMode);
}