Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error The entity type AuditLog is not part of the model for the current context #152

Open
Max1825 opened this issue Aug 22, 2017 · 7 comments

Comments

@Max1825
Copy link

Max1825 commented Aug 22, 2017

Hello sir, big fan of your work but I ran in to this error, I build a project using asp.net with Entity Framework, I already install your tracker like 4-steps-tut (very easy to install..), but when I run project, right after db.SaveChanges() code got this error : "The entity type AuditLog is not part of the model for the current context " ..
Any ideas to fix this sir?...thank you so much.

@Bemjamin
Copy link

Bemjamin commented Aug 22, 2017

Just create manually the tables or you can create a configuration files to override the default table configuration like:

public class CustomTraceAuditLogConfiguration : EntityTypeConfiguration
{
public TraceAuditLogConfiguration()
{
ToTable("YOURTABLE")
.HasKey(e => e.AuditLogId)
.Property(x => x.AuditLogId).HasColumnName("AUDITLOGID");
Property(x => x.EventDateUTC).HasColumnName("EVENTDATEUTC");
Property(x => x.EventType).HasColumnName("EVENTTYPE");
Property(x => x.RecordId).HasColumnName("RECORDID");
Property(x => x.TypeFullName).HasColumnName("TYPEFULLNAME");
Property(x => x.UserName).HasColumnName("USERNAME");
}
}

And add the configuration to your Context in your OnModelCreating method:

modelBuilder.Configurations.Add(new CustomTraceAuditLogConfiguration());

@Max1825
Copy link
Author

Max1825 commented Aug 23, 2017

Sorry @Bemjamin , i follow your step but it still don't work, i already create a table 1st but don't work, next i build a configuration files to override the default table configuration but it still run into error:
capture3
capture4
Any idea sir...:(

@Bemjamin
Copy link

Can you show your dbcontext class? I did this at work and it is working.

@Max1825
Copy link
Author

Max1825 commented Aug 23, 2017

Here @Bemjamin
capture5
Thank you so much for helping...

@Bemjamin
Copy link

Well, the differences are:
I am not using the same dbcontext type as you, I am using the normal TrackerContext.
I am only using fluent mapping for all tables
I am creating the mapping for both tables: AuditLog and AuditLogDetails
I am setting the database intializer to null, in your constructor you can put:

Database.SetInitializer<MyContext>(null);

I hope it helps.

@me-jason-dot
Copy link

Here @Bemjamin
capture5
Thank you so much for helping...

Hi, was this ever resolved - I'm having the same issue here. Thanks.

@bennetmathew
Copy link

I am also facing the same issue. Any solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants