bilal-fazlani / tracker-enabled-dbcontext

Tracker-enabled DbContext offers you to implement full auditing in your database
https://tracker-enabled-dbcontext.bilal-fazlani.com/
Other
217 stars 110 forks source link

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

Open Max1825 opened 7 years ago

Max1825 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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

Max1825 commented 7 years ago

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

Bemjamin commented 7 years ago

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 commented 5 years ago

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

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

bennetmathew commented 4 years ago

I am also facing the same issue. Any solution?