question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

System.InvalidOperationException: 'The entity type AuditLog is not part of the model for the current context.'

See original GitHub issue

Describe 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:closed
  • Created 3 years ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
djhvscfcommented, Dec 3, 2020

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

0reactions
djhvscfcommented, Dec 3, 2020

Do you have an example where we can use two dbcontext? @thepirat000

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found