目前我正在寻找一种方法来查找[context] .SubmitChanges()中实体的旧值。Linq to SQL - 审计跟踪(在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);
}
[Linq to SQL:获取已更改行的旧值]的可能重复(http://stackoverflow.com/questions/1852533/linq-to-sql-getting-old-values-of-changed-rows) – 2012-02-06 09:46:21
@WouterdeKort我确实看到帖子,但没有说明如何获取缓存。另外,当我查看我的SubmitChanges时,即使没有调用刷新,我也会看到新的值。 – Julian 2012-02-06 10:06:40