EntityFrameworkCore Audit Exclude

huangapple go评论45阅读模式
英文:

EntityFrameworkCore Audit Exclude

问题

I'm using Z.EntityFramework.Plus to audit my database changes.

To include what entities I want to follow, I'm using the next configuration:

AuditManager.DefaultConfiguration.Exclude(x => true); // Exclude ALL
AuditManager.DefaultConfiguration.Include<Customer>();

With above code all entities of type Customer are audited.

But now, I want to audit only certain customers. For example, I would like to audit only active customers. So, only customers with property IsActive=true should be audited.

I tried using something like the following:

AuditManager.DefaultConfiguration.Exclude(w => w.GetType() == typeof(Customer) && ((Customer)w).IsActive);

But the above doesn't work.

Where can I add a condition to exclude all inactive customers from audit tables?

Thanks in advance!

英文:

I'm using Z.EntityFramework.Plus to audit my database changes.

To include what entities I want to follow, I'm using the next configuration:

AuditManager.DefaultConfiguration.Exclude(x =&gt; true); // Exclude ALL
AuditManager.DefaultConfiguration.Include&lt;Customer&gt;();

With above code all entities of type Customer are audited.

But now, I want to audit only certain customers. For example, I would like to audit only active customers. So, only customers with property IsActive=true should be audited.

I tried using something like the following:

AuditManager.DefaultConfiguration.Exclude(w =&gt; w.GetType() == typeof(Customer) &amp;&amp; ((Customer)w).IsActive);

But the above doesn't work.

Where can I add a condition to exclude all inactive customers from audit tables?

Thanks in advance!

答案1

得分: 0

这是目前尝试排除/包含实体的一种聪明方法,但由于这些代码行,库不支持:https://github.com/zzzprojects/EntityFramework-Plus/blob/master/src/shared/Z.EF.Plus.Audit.Shared/AuditConfiguration/IsAuditedEntity.cs#L38-L41

然而,如果您在GitHub问题跟踪器上提出请求,您的情况可能会得到支持(请确保引用此帖子)。

由于这会使每个实体的审计检查变慢,我们无法默认支持它,但我们可以添加一个选项来启用此功能。

英文:

That is currently a smart way to try to exclude/include entities, but not supported by the library because of those lines of code: https://github.com/zzzprojects/EntityFramework-Plus/blob/master/src/shared/Z.EF.Plus.Audit.Shared/AuditConfiguration/IsAuditedEntity.cs#L38-L41

However, your case could be supported if you ask for it on the GitHub Issue Tracker (Make sure you reference this post)

We cannot support it by default as it makes the check for every entity if we should audit it or not slower, but we can add an option that will enable this.

huangapple
  • 本文由 发表于 2023年3月8日 19:24:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/75672393.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定