I have a custom initializer setup as follows:
public class PromptIfChangesNeededDBInitializer : IDatabaseInitializer<MeyerREContext> { public PromptIfChangesNeededDBInitializer() {
Here is my DbContext class
public class MeyerREContext : DbContext { static MeyerREContext() { Database.SetInitializer(new PromptIfChangesNeededDBInitializer()); } public DbSet<Address> Addresses { get; set; } ... More DbSet property definitions protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Configurations.Add(new AddressMap()); ... More Configurations } }
This is the first context call.
City city = dbNew.Cities.Where(e=>e.CityName=="Foley").FirstOrDefault();
The initializer constructor is called properly, as confirmed by the breakpoint, OnModelCreating is executed correctly, as confirmed by the breakpoint, but after OnModelCreating is complete, database initialization is never called ...
I removed Database.SetInitializer (new PromptIfChangesNeededDBInitializer () call) from ctor DBContext to ctor of the calling class before any context calls, and now I have a slightly different behavior:
public class CreateData { private VFPModelContainer db = new VFPModelContainer(); private MeyerREContext dbNew; public CreateData() { Database.SetInitializer(new PromptIfChangesNeededDBInitializer<MeyerREContext>()); dbNew = new MeyerREContext(); dbNew.Database.Initialize(force: true); NUll Exception here now... }
An exceptional exception is now provided in the EF Framework code:
Here is a detailed description of the exception:
System.NullReferenceException occurred Message=Object reference not set to an instance of an object. Source=EntityFramework StackTrace: at System.Data.Entity.ModelConfiguration.Configuration.Properties.Navigation.NavigationPropertyConfiguration.ValidateConsistency(NavigationPropertyConfiguration navigationPropertyConfiguration)
InnerException:
It looks like the exception occurs in one of the EntityTypeConfiguration calls, but is some exception swallowed? How can I determine which challenge it is? There are about 100 objects in this model.

How to get more information about what went wrong inside EF? I need to know which navigation property has problems ... I think the problem is that EF creates workflow threads to create and validate the model, but I donβt understand why the exception is soooo undefined ??
Any ideas?
Thanks Greg