Is it possible to use Audit.Net without managing Audit_{Entity}s separately? #595
Unanswered
amirrezayati
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Config:
The most desired behaviour would be the following:
You create a new {Entity} and you add it to the DbContext model
Add-Migration creates the table for the {Entity} and it would automatically create an Audit_{Entity} table as well, that would contain properties of the {Entity} + the properties of the IAuditableEntity interface
But as thepirat000 commented to the question: Dynamic audit table creation via Migrations
The library does not provide any custom migration.
So if I am not mistaken this means you need to create the Audit_{Entity} for every {Entity} to
let Audit.Net know how to map {Entity} -> Audit_{Entity}
let EF know what tables to create
like thepirat000's following example with User and Audit_User classes: https://stackoverflow.com/a/51941354/11213440
Adding properties of the IAuditableEntity interface to the Audit_{Entity} is fine, and can be easily maintained, refactored later on. But what about the properties of the {Entity}?
It is a very possible situation that with future developments we add a new important property to the {Entity} and we (as we are humans) forget to make the exact changes on the Audit_{Entity}. This could lead to a situation where the fact of the forgotten update on the Audit_{Entity} turns out like weeks or months later, and logs created in that period of time would lack this new property.
So my idea was for the Audit_{Entity} is to be inherited from the {Entity} besides implementing the IAuditableEntity interface, to prevent the situation presented a few lines before.
But this results in the following problem:
Choosing inheritation from the {Entity} means I can make decision between Table-per-Hierarchy or Table-per-Type (as Table-per-Concrete Type is not supported in EF Core 5 yet). Both results in storing the Audit_{Entity} entries in the same table, which I would not like to do since searching in a table with 500,000 rows could be really painful.
So the question:
How could I maintain Audit_{Entity}s without editing them separately every time I make changes on the model?
Beta Was this translation helpful? Give feedback.
All reactions