I have created a context class that implements DbContext “BeerRecommenderContext” and an intializer that implements
DropCreateDatabaseAlways<BeerRecommenderContext>
When I run/debug the project, the entity framework does not not drop the old database and create a new one so changes in model are not reflected which causes problems. I then manually delete the database and rerun and the entity framework doesn’t create the database. I run it a second time and the entity framework successfully builds the new database. I’m not very familiar with connection strings so it could be an issue there:
<add name="BeerRecommenderContext"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;
database=BeerRecommenderContext.mdf;
AttachDBFilename=|DataDirectory|BeerRecommenderContext.mdf;
User Instance=true"
providerName="System.Data.SqlClient" />
In the Application_Start method of my Global.asax.cs file I have added the line
Database.SetInitializer<BeerRecommenderContext>(new BeerRecommenderInitializer());
How do I get DropCreateDatabaseAlways to perform properly?
I found that adding Database.SetInitializer to the Application_Start to not work every time.
I add a static constructor to the DbContaxt which calls Database.SetInitializer