1

Configuring Audit.EntityFramework with the below configuration (part of Audit.Net) does not result in the proper mapping of entities. Audit.EntityFramework.Configuration.Setup().ForContext<AuditAudiCCPContext>().UseOptOut();

The method

public override object InsertEvent(AuditEvent auditEvent)

of EntityFrameworkDataProvider.cs returns without any exception because it is unable to find the mapped entity. Line 96 of EntityFrameworkDataProvider.cs:

var mappedType = _auditTypeMapper?.Invoke(type, entry);

which attempts to map the entity to the audited entity fails to produce any result.

I tried the following other configurations

a.

Audit.EntityFramework.Configuration.Setup()
        .ForContext<AuditAudiCCPContext>(config => config
         .ForEntity<SubjectInfo>(_=>_.Ignore(e=>e.Ticket).Ignore(e=>e.LevelSubjectMap))
        .AuditEventType("{context}:{database}"))
        .UseOptIn();

b. The suggestions in this post -How do I target another database with Audit.Net - Audit.EntityFramework.Core

c. I am unable to use the method UseEntityFramework on Setup() because it is unavailable.

It should create an entry in the audit database table, but that does not happen. There are no exceptions either.

Cindy Meister
  • 25,071
  • 21
  • 34
  • 43

1 Answers1

0

You are basically missing to configure the EntityFramework Data Provider.

You must call the .UseEntityFramework() extension method to configure the mapping between your data entities and your audit entities, for example:

using Audit.Core;

Audit.Core.Configuration.Setup()
    .UseEntityFramework(_ => _
        .AuditTypeExplicitMapper(map => map
            .Map<SubjectInfo, SubjectInfo_Audit>()
            .Map<xxxx, xxxx_Audit>()));

Also here some configuration examples.

thepirat000
  • 12,362
  • 4
  • 46
  • 72