我试图跟踪覆盖SaveChanges()
方法的数据库的所有更改。
我的问题是如何获得新旧价值:
var addedEntities = ctx.ChangeTracker.Entries().Where(x => x.State == EntityState.Added).Select(x => x.Entity);
var modifiedEntities = ctx.ChangeTracker.Entries().Where(x => x.State == EntityState.Modified).Select(x => x.Entity);
var deletedEntities = ctx.ChangeTracker.Entries().Where(x => x.State == EntityState.Deleted).Select(x => x.Entity);
foreach (var added in addedEntities)
{
}
foreach (var modified in modifiedEntities)
{
}
foreach (var deleted in deletedEntities)
}
}
在这些循环中,我必须检索已更改的实体的旧值和新值。我怎样才能实现它?