审核 Audit.NET 中的 n 到 m 关系(数据库优先)
Auditing n to m relationships in Audit.NET (DB-first)
我正在将 Audit.NET/EF 添加到遗留的 DB-first 项目。 (它使用从数据库模式构建的 edmx 文件来生成域模型。)
数据库在 table A 和 table B 之间有一个多对多关系,像往常一样使用链接 table A_B 建模。然而,生成的域模型没有 A_B class。相反,A 有一个 Bs 的容器,B 有一个 As 的容器。
我发现 Audit.NET 没有看到 A 和 B 之间关联的更改。 (它确实看到了对 A 字段或 B 字段的更改)。
我错过了什么吗?或者这在 Audit.NET 中根本不可能吗?
请检查 issue #78
您需要将 IncludeIndependantAssociations
设置设为 true,以包括独立关联(没有连接实体的多对多关系):
Audit.EntityFramework.Configuration.Setup()
.ForAnyContext(cfg => cfg
.IncludeIndependantAssociations());
请注意,它们记录在 EntityFrameworkEvent.Associations
事件输出的不同 属性 中
Audit.Core.Configuration.AddOnCreatedAction(scope =>
{
var associations = scope.GetEntityFrameworkEvent().Associations;
// ...
});
我正在将 Audit.NET/EF 添加到遗留的 DB-first 项目。 (它使用从数据库模式构建的 edmx 文件来生成域模型。)
数据库在 table A 和 table B 之间有一个多对多关系,像往常一样使用链接 table A_B 建模。然而,生成的域模型没有 A_B class。相反,A 有一个 Bs 的容器,B 有一个 As 的容器。
我发现 Audit.NET 没有看到 A 和 B 之间关联的更改。 (它确实看到了对 A 字段或 B 字段的更改)。
我错过了什么吗?或者这在 Audit.NET 中根本不可能吗?
请检查 issue #78
您需要将 IncludeIndependantAssociations
设置设为 true,以包括独立关联(没有连接实体的多对多关系):
Audit.EntityFramework.Configuration.Setup()
.ForAnyContext(cfg => cfg
.IncludeIndependantAssociations());
请注意,它们记录在 EntityFrameworkEvent.Associations
Audit.Core.Configuration.AddOnCreatedAction(scope =>
{
var associations = scope.GetEntityFrameworkEvent().Associations;
// ...
});