Where to put Audit.Core.Configuration.Setup()
See original GitHub issueWhere can/should this get called? I could not find in the readme the location to call Audit.Core.Configuration.Setup()
.
I first tried calling Audit.Core.Configuration.Setup()
in the database context OnModelCreating()
, and the audit table was created. However, there were some null errors when trying to save to the audit table.
Second, I tried tried calling Audit.Core.Configuration.Setup()
in the database context OnConfiguring()
, since I saw it in another issue. That resulted in the audit table being deleted, so that doesn’t seem like the right place.
Your configuration call to
Audit.Core.Configuration.Setup()
should be done only once, at the startup of your application.
_Originally posted by @thepirat000 in https://github.com/thepirat000/Audit.NET/issues/247#issuecomment-539686730_
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (4 by maintainers)
Top GitHub Comments
Thank you, I fixed by adding an explicit key property to the
Audit_*
model classes so that theId
matched up with the audited model and EF Core uses the explicit key property for its tracking purposes.e.g.
I think your library is wonderful and appreciate your work to create and maintain it.
I don’t know what the users of the library usually do. There are many data providers for the audit output saving, and there are many use cases for the EntityFramework data provider.
For the DI part, you should be able to access any of your registered services, or the
IServiceProvider
as a parameter on yourStartup.Configure()
method and then use it on the setup delegate, for example:or if it’s a singleton, you could just:
Is the
DbSet
you need to access on the sameDbContext
that is being audited? If so, you can access it withGetDbContext()
method on the EF event: