Audit.Net - Find all audits of a given entity

208 Views Asked by At

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

There are 1 best solutions below

2
thepirat000 On BEST ANSWER

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);