英文:
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 => 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!
答案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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论