I am trying to log changes to the database so that the user can see who changed what. I am using the DbEntityEntry
to go through and log the DbPropertyEntity
that have been modified. I am running into a problem when I want to log changes to a navigation property. I use the Reference()
method to get reference to the navigation property, however unlike DbPropertyEntity
, DbReferenceEntry
does not have a OriginalValue
only a CurrentValue
attribute. How do you get the OriginalValue
of a navigation property?
//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, ???);
}