【发布时间】:2019-03-26 12:59:24
【问题描述】:
我是 Audit.net 的新手。我在我的项目中成功配置了它。
但是现在,我需要扩展它以保存额外的信息,例如 requesterID 和视图页面上的评论。
我的情况: 实体映射到 Entity_AT
Entity {
[Key]
int ID
string label
}
Entity_AT {
[Key]
int ATID
int ID
string label
int ATFlag
datetime ATCreationDate
string RequesterID
string ATComment
}
public void Add(TEntity obj, string RequesterId)
{
_dbSet.Add(obj);
_context.SaveChanges();
}
[AuditDbContext(Mode = AuditOptionMode.OptOut, IncludeEntityObjects = false, AuditEventType = "{database}_{context}")]
public class MyDBContext : AuditIdentityDbContext<ApplicationUser>
{
}
Audit.Core.Configuration.DataProvider = new EntityFrameworkDataProvider()
{
AuditTypeMapper = t => t == typeof(Entity) ? typeof(Entity_AT) : null,
AuditEntityAction = (evt, entry, auditEntity) =>
{
var a = (dynamic)auditEntity;
a.ATCreationDate = DateTime.UtcNow;
a.ATFlag = (entry.Action == "Insert") ? 1 : (entry.Action == "Update") ? 2 : (entry.Action == "Delete") ? 3 : 0;
return true; // return false to ignore the audit
}
};
我试过了:
_context.AddAuditCustomField("RequesterId", requesterId);
_context.AddAuditCustomField("ATComment", "pippo");
_dbSet.Add(obj);
_context.SaveChanges();
但没有结果
【问题讨论】:
标签: c# entity-framework-core audit-trail audit.net