代码首先跟踪数据库更改

时间:2016-02-29 13:43:11

标签: c# ef-code-first

我试图跟踪覆盖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)
}
}

在这些循环中,我必须检索已更改的实体的旧值和新值。我怎样才能实现它?

0 个答案:

没有答案