【问题标题】:Audit.Net:Setup().ForContext<MyContext>() results in no entities being mappedAudit.Net:Setup().ForContext<MyContext>() 导致没有实体被映射
【发布时间】:2019-09-12 03:11:42
【问题描述】:

使用以下配置(Audit.Net 的一部分)配置 Audit.EntityFramework 不会导致实体的正确映射。 Audit.EntityFramework.Configuration.Setup().ForContext&lt;AuditAudiCCPContext&gt;().UseOptOut();

方法

public override object InsertEvent(AuditEvent auditEvent)

of EntityFrameworkDataProvider.cs 无任何异常返回,因为它无法找到映射的实体。 EntityFrameworkDataProvider.cs的第96行:

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

试图将实体映射到被审计实体未能产生任何结果。

我尝试了以下其他配置

一个。

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

b.这篇文章中的建议-How do I target another database with Audit.Net - Audit.EntityFramework.Core

c。我无法在Setup() 上使用方法UseEntityFramework,因为它不可用。

它应该在审计数据库表中创建一个条目,但这不会发生。也不例外。

【问题讨论】:

    标签: c# entity-framework configuration audit.net


    【解决方案1】:

    您基本上缺少配置EntityFramework Data Provider

    您必须调用.UseEntityFramework()扩展方法来配置您的数据实体和您的审计实体之间的映射,例如:

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

    还有here一些配置示例。

    【讨论】:

      猜你喜欢
      • 2013-08-29
      • 2013-03-26
      • 2014-10-21
      • 2013-03-04
      • 1970-01-01
      • 2012-05-25
      • 2011-07-13
      • 2020-11-05
      • 1970-01-01
      相关资源
      最近更新 更多