【发布时间】:2018-03-15 19:42:35
【问题描述】:
我有类似这样的课程:
public class foo{
public string FooProp1 {get; set;}
public Bar Bar{get; set;}
}
public class Bar{
public string BarProp1 {get; set;}
public string BarProp2 {get; set;}
}
我有一些审核设置,如果我更新 Foo,那么我可以获得除“Bar”之外的所有属性的属性名称和值。有没有办法获取“BarProp1”的属性名称和值。
private void ProcessModifiedEntries(Guid transactionId) {
foreach (DbEntityEntry entry in ChangeTracker.Entries().Where(t => t.State == EntityState.Modified).ToList()) {
Track audit = CreateAudit(entry, transactionId, "U");
foreach (var propertyName in entry.CurrentValues.PropertyNames) {
string newValue = entry.CurrentValues[propertyName]?.ToString();
string originalValue = entry.OriginalValues[propertyName]?.ToString();
SetAuditProperty(entry, propertyName, originalValue, audit, newValue);
}
}
}
我想在 Foo 更改时审核 BarProp1。
【问题讨论】:
-
如果
BarProp1被修改,它已经被报告了,因为Bar也是Modified。 -
无栏未修改。只有 foo 属性已被修改但我想获取 bar 属性的值,因为我想为其他目的审核 Bar 属性值。
-
然后定义一个接口,该接口规定了一个(未映射的)计算属性,其中包含用于审计的附加信息。
-
我是 C# 新手,请您简单解释一下。所以我可以创建一个接口,我的 foo 类将从那里继承,在审计中我可以检查我的 foo 类是 ISomeInterface 然后我可以执行一些逻辑。但是我应该在接口中添加什么。
标签: c# entity-framework c#-4.0 audit