I'm trying to add auditing to my application. The problem that I encountered is that I can not get some old and new values from non primitive types. For example, if I have an entity Person, I can easily get name, age, but I can not get any property of the Country:
public class Person
{
public string Name { get; set;}
public int Age { get; set; }
public Country { get;set;}
}
and country might look like:
public class Country
{
public int Id { get;set;}
public string Name { get;set;}
}
Currently the code that returns new/old value looks like (dbEntry is DbEntityEntry):
foreach (var prop in dbEntry.CurrentValues.PropertyNames)
{
string oldValue = dbEntry.OriginalValues.GetValue<object>(prop) == null ? null : dbEntry.OriginalValues.GetValue<object>(prop).ToString();
string newValue = dbEntry.CurrentValues.GetValue<object>(prop) == null ? null : dbEntry.CurrentValues.GetValue<object>(prop).ToString();
}
How can I get information related to the country (I want to have country name in this case)?