0
我試圖添加審計到我的應用程序。我遇到的問題是我無法從非原始類型中獲得一些新舊值。舉例來說,如果我有一個實體的人,我可以輕鬆搞定的姓名,年齡,但我不能讓任何國家的財產:實體框架審計
public class Person
{
public string Name { get; set;}
public int Age { get; set; }
public Country { get;set;}
}
和國家可能看起來像:
public class Country
{
public int Id { get;set;}
public string Name { get;set;}
}
目前返回新/舊值的代碼如下所示(dbEntry是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();
}
如何,我可以得到相關的國家(我想在這種情況下,有國名)的信息?
不,我實現了自己的解決方案。您建議的圖書館是否跟蹤館藏中的任何變化? – Daemon025 2014-11-02 12:55:51
如果你的意思是跟蹤收藏中的實體,那麼是的。我寫我的自我btw。雖然我不確定我是否正確理解你的問題。 – 2014-11-08 08:45:03
這是另一個:[Audit.EntityFramework](https://www.nuget.org/packages/Audit.entityframework/) – thepirat000 2016-09-09 04:37:23