System.InvalidOperationException: 'The entity type AuditLog is not part of the model for the current context.'
See original GitHub issueDescribe the bug Using the default configuration for EntityFramework extension it is throwing an exception
To Reproduce This is the configuration running under Application_Start method.
Audit.Core.Configuration.Setup()
.UseEntityFramework(_ => _
.UseDbContext<PuertaAPuertaContext>()
.AuditTypeMapper(t => typeof(AuditLog))
.AuditEntityAction<AuditLog>((ev, entry, entity) =>
{
entity.AuditId = Guid.NewGuid();
entity.AuditChanges = JsonConvert.SerializeObject(entry.Changes, Audit.Core.Configuration.JsonSettings);
entity.AuditData = entry.ToJson();
entity.TableName = entry.EntityType.Name;
entity.AuditDate = DateTime.Now;
entity.AuditUser = Environment.UserName;
entity.AuditAction = entry.Action;
var pk = entry.PrimaryKey?.FirstOrDefault().Value?.ToString();
entity.TablePk = string.IsNullOrWhiteSpace(pk) ? string.Empty : pk;
})
.IgnoreMatchedProperties(true));
Expected behavior Changes should be saved in table specified.
Libraries (specify the Audit.NET extensions being used including version):
- Audit.EntityFramework: 16.2.0
Target .NET framework:
- .NET Framework 4.7.2
Additional context System.InvalidOperationException: ‘The entity type AuditLog is not part of the model for the current context.’
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (4 by maintainers)
Top Results From Across the Web
The entity type <type> is not part of the model for ...
System.InvalidOperationException: The entity type Estate is not part of the model for the current context. It happens when I am trying to access ......
Read more >The entity type AuditLog is not part of the model for ...
I intermittently get the following error: System.InvalidOperationException: The entity type AuditLog is not part of the model for the current ...
Read more >The entity type PopularToys is not part of the model for ...
Core and Nop.Data). Now when I try to fetch this table I get following error: The entity type PopularToys is not part of...
Read more >Entity type is not part of the model for the current context….
1). Check that your properties are nullable. In the Edmx select each field and then click properties(should be next to solution explorer in...
Read more >Login Exception when using Custom Data Module #521
InvalidOperationException : The entity type AuditLog is not part of the model for the current context. em System.Data.Entity.Internal.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I finally did it based on this answer: https://stackoverflow.com/questions/50537401/setting-up-for-selective-auditing-in-same-dbcontext
Close this issue now. Appreciate your help
Do you have an example where we can use two dbcontext? @thepirat000