When an exception is thrown from a custom convention the database is put into a bad state that causes the Initializer to not run. <br /><br />Repro:<br />Create an console application following the standard blog/post/comment model (source code is attached)<br />Add a convention to the DbContext that throws an exception<br />e.g.<br /> modelBuilder.Conventions.Add(<br /> entities => entities<br /> .Configure(c => c.ToTable(c.ClrType + "_table")));<br />run<br />change convention so it no longer throws an exception<br /> modelBuilder.Conventions.Add(<br /> entities => entities<br /> .Configure(c => c.ToTable(c.ClrType.Name + "_table")));<br />run <br />note exception is thrown: <br />Model compatibility cannot be checked because the database does not contain model metadata. Model compatibility can only be checked for databases created using Code First or Code First Migrations.<br /><br /><br />expected behavior: Initializer should either drop the database or not create it in the case of an exception in the conventions
↧