简体   繁体   English

在 Audit.NET 中审计 n 到 m 关系(DB 优先)

[英]Auditing n to m relationships in Audit.NET (DB-first)

I'm adding Audit.NET /EF to a legacy DB-first project.我正在将Audit.NET /EF 添加到旧的 DB-first 项目中。 (It uses an edmx file built from the database schema to generate the domain model.) (它使用从数据库模式构建的 edmx 文件来生成域模型。)

The DB has a many-to-many relationship between table A and table B modeled as usual with a linking table A_B.数据库在表 A 和表 B 之间具有多对多关系,通常使用链接表 A_B 建模。 The domain model generated however doesn't have an A_B class.然而,生成的域模型没有 A_B 类。 Instead, A has a container of Bs, and B has a container of As.相反,A 有一个 B 的容器,B 有一个 As 的容器。

I'm finding that changes to the associations between A and B are not being seen by Audit.NET.我发现 Audit.NET 没有看到 A 和 B 之间关联的更改。 (It does see the changes to A fields or B fields). (它确实看到了对 A 字段或 B 字段的更改)。

Am I missing something?我错过了什么吗? Or is this simply not possible in Audit.NET?或者这在 Audit.NET 中根本不可能?

Ref: GitHub Audit.NET issue参考: GitHub Audit.NET 问题

Please check the issue #78请检查问题 #78

You need to set the IncludeIndependantAssociations setting to true, to include the independant associations (many-to-many relations without a join entity):您需要将IncludeIndependantAssociations设置设置为 true,以包含独立关联(没有连接实体的多对多关系):

Audit.EntityFramework.Configuration.Setup()
    .ForAnyContext(cfg => cfg
        .IncludeIndependantAssociations());

Note they are logged in a different property of the event output on EntityFrameworkEvent.Associations请注意,它们记录在EntityFrameworkEvent.Associations事件输出的不同属性中

Audit.Core.Configuration.AddOnCreatedAction(scope =>
{
    var associations = scope.GetEntityFrameworkEvent().Associations;
    // ...
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM