我正在尝试记录对数据库的更改,以便用户可以看到谁更改了什么。我正在使用DbEntityEntry
来查看并记录DbPropertyEntity
已修改的内容。当我想记录对导航属性的更改时遇到了问题。我使用该Reference()
方法来获取对导航属性的引用,但与 不同的是DbPropertyEntity
, DbReferenceEntry
它没有OriginalValue
唯一的CurrentValue
属性。你如何获得OriginalValue
导航属性?
//Get the field that hold the id of the foreign key
var field = entry.Property(x => x.field);
//Check to see if the user changed the value
if (field.IsModified)
{
//Get the reference property associated with the field
var fieldRef = entry.Reference(x => x.fieldRef);
//Log the id change
Log(field.Name, field.CurrentValue, field.OriginalValue);
//Can't get the OriginalValue
Log(fieldRef.Name, fieldRef.CurrentValue, ???);
}