Quantcast
Channel: Entity Framework
Viewing all articles
Browse latest Browse all 10318

Edited Issue: DropCreateDatabaseIfModelChanges initialzer doesn't work in some cases [640]

$
0
0
When an exception is thrown from a custom convention the database is put into a bad state that causes the Initializer to not run.

Repro:
Create an console application following the standard blog/post/comment model (source code is attached)
Add a convention to the DbContext that throws an exception
e.g.
modelBuilder.Conventions.Add(
entities => entities
.Configure(c => c.ToTable(c.ClrType + "_table")));
run
change convention so it no longer throws an exception
modelBuilder.Conventions.Add(
entities => entities
.Configure(c => c.ToTable(c.ClrType.Name + "_table")));
run
note exception is thrown:
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.


expected behavior: Initializer should either drop the database or not create it in the case of an exception in the conventions

Viewing all articles
Browse latest Browse all 10318

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>