peterrus
peterrus

Reputation: 651

DropCreateAlways database initializer does not work when put in Web.config

I have the following in my Web.config

<entityFramework>
  <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
  <contexts>
    <context type="Models.EVRMDBContext, EVRM">
      <databaseInitializer type="System.Data.Entity.DropCreateAlways`1[[Models.EVRMDBContext, EVRM]], EntityFramework" />
    </context>
  </contexts>
</entityFramework>

However as soon as I use/query my DBContext the database is not created. When I set the databaseInitializer in Global.asax using

System.Data.Entity.Database.SetInitializer(new System.Data.Entity.DropCreateDatabaseAlways<EVRM.Models.EVRMDBContext>());

It does initialize the database.

(Using Entity Framework 5 with MVC4)

Upvotes: 1

Views: 859

Answers (1)

Bjorn
Bjorn

Reputation: 1110

There's a typo in the web.config, should be "System.Data.Entity.DropCreateDatabaseAlways" instead of "System.Data.Entity.DropCreateAlways"

Upvotes: 1

Related Questions