Why doesn't the Entity Framework recreate my localdb when uninstalling?

Using Entity Framework 6 using the first model installation using

  • The connection string is not specified.
  • A simple single POCO class for a model.

Run the application created by the database. Woot!

Delete .mdf / .ldf in the App_Data folder.

Launch application, error connecting to database.

Why didn't he recreate the database?

PS I tried to do. How to recreate the database for the Entity Framework? but that will not work.

So, how can I convince EF to recreate the database (and why is it difficult?)?

+4
source share
2 answers

, , MDF Windows. SQL Server LocalDb , , , MDF.

, SQL Server Management Studio SQL Server Visual Studio.

" " Visual Studio Solution Explorer, MDF App_Data, , Solution Explorer. Visual Studio, , SQL Server .

+6

DbContext , , :

        Database.SetInitializer<MyContext>(new CreateDatabaseIfNotExists<MyContext>());
        Database.SetInitializer<MyContext>(new DropCreateDatabaseIfModelChanges<MyContext>());
        Database.SetInitializer<MyContext>(new DropCreateDatabaseAlways<MyContext>());

DbContext.

+10

All Articles