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