Audit.Net – 查找特定实体的所有审计记录

huangapple go评论74阅读模式
英文:

Audit.Net - Find all audits of a given entity

问题

我正在使用Audit.NetEntity Framework Data Provider

我在应用程序数据中使用一个数据库,以及用于审计的不同数据库(和DbContext)。

在核心配置中,我像这个例子中设置了显式映射:

config.AuditTypeExplicitMapper(m =>
{
    m.Map<Client, ClientAudit>();
    m.AuditEntityAction<IAuditEntity>(SetAuditEntity);
});

一切正常。但是以后,我想加载一个实体,然后查看该实体的所有审计记录。

我容易做的是使用实体的Id查询审计上下文。但是,我需要事先知道从我的应用程序上下文到我的审计上下文的映射。

我的意思是,查找Client实体时,使用了ClientAudit实体。Audit.Net是否提供了这个可能性?

我尝试直接查看Audit.Net的代码和文档,但是找不到可以直接给我这个结果的信息。

在网上搜索,我找不到类似的信息。看起来我是第一个尝试实现这个的人。

英文:

I am using Audit.Net with Entity Framework Data Provider.

I am using one database for the application data and a different database (and DbContext) for the audits.

In the core configuration, I am seetting the the explicit mapper as in this example:

config.AuditTypeExplicitMapper(m =>
{
    m.Map<Client, ClientAudit>();
    m.AuditEntityAction<IAuditEntity>(SetAuditEntity);
});

Everything works fine. However later on I would like to load an entity and then see all audits for that entity.

What I easily do is query the Audit context with the Id of the entity. But then I need to know before hand the mappings from my Application context to my Audit context.

What I mean is. Find that for the Client entity, the ClientAudit entity is used. Does Audit.Net offers this possibility?

I tried looking directly in the Audit.Net code and documentation, but I found nothing that would give me this direct result.

Searching online I found no similar information. Seems I am the first to try to accomplish this.

答案1

得分: 0

如果您使用显式映射器,可以通过在EF数据提供程序中使用AuditTypeMapper属性来获取映射类型,例如:

var dataProvider = (EntityFrameworkDataProvider)Audit.Core.Configuration.DataProvider;
var auditType = dataProvider.AuditTypeMapper.Invoke(typeof(Client), null);
英文:

If you use the Explicit Mapper, you can get the mapped type by using the AuditTypeMapper property in the EF data provider, for example:

var dataProvider = (EntityFrameworkDataProvider)Audit.Core.Configuration.DataProvider;
var auditType = dataProvider.AuditTypeMapper.Invoke(typeof(Client), null);

huangapple
  • 本文由 发表于 2023年7月4日 22:32:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/76613666.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定