-
-
Notifications
You must be signed in to change notification settings - Fork 332
Migration doesn't create Audit_ tables #596
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
Does your DbContext have a public property of type |
The most desired behaviour would be the following: You create a new {Entity} and you add it to the DbContext model 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} 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? |
any ideas? |
There isn't a generic way of accomplishing what you want, and I think it's beyond the scope of this library. Nevertheless, I guess you could hook into the migrations in some way (check this EF open issue) to replicate the operations to the audit tables, but that will not be easy since you will have to handle all the different operation combinations and generate the Sql for each one. I've also found this post that summarizes the different ways of hooking into the EF migrations. |
Config:
i have some entity on mydbcontext i have after migration create two table per entity
for example :
dbset products
in sql table :
Products
Audit_Products
The text was updated successfully, but these errors were encountered: