我正在使用Audit.EntityFramework.Core,在这里我通过使用DbContextHelper,IAuditDbContext并重写SaveChanges()和SaveChangesAsync()方法来实现审核,而不是继承AuditDbContext 。
public partial class MyContext: DbContext
{
private static DbContextHelper _helper = new DbContextHelper();
private readonly IAuditDbContext _auditContext;
public MyContext(DbContextOptions<MyContext> options) : base(options)
{
_auditContext = new DefaultAuditContext(this);
_helper.SetConfig(_auditContext);
}
public override int SaveChanges()
{
return _helper.SaveChanges(_auditContext, () => base.SaveChanges());
}
public override async Task<int> SaveChangesAsync(CancellationToken cancellationToken = default(CancellationToken))
{
return await _helper.SaveChangesAsync(_auditContext, () => base.SaveChangesAsync(cancellationToken));
}
}
我的要求是向审核添加一些自定义字段
,但是由于我不继承AuditDbContext,所以我无权访问context.AddAuditCustomField("key", object);
我试图手动添加AddAuditCustomField()的实现,但是我不知道evt.CustomFields [“ sample”]和ExtraFields [“ sample”]之间的联系。
_context.AddAuditCustomField("Sample", sample);
`
a.RequesterID = evt.CustomFields["Sample"] as string;
我是这个图书馆的新手,请帮助我。谢谢。