I'm trying to get a MVC 3 deployment off the ground under the Azure trial, but seem to have hit a wall with getting the EF4.1 database to create itself.
When running, it will connect successfully, but give the error:
Invalid object name 'dbo.TableName'.
I believe this is because the DB exists, but there are no tables in it. I've been able to reproduce it locally - The DB recreation works fine if I delete my SQL Express DB, but not if I then delete all tables and leave the DB.
I've read up on the methods that can be added to Global.asax:
protected void Application_Start()
{
// Use any of:
System.Data.Entity.Database.SetInitializer<MyDatabaseContext>(new DropCreateDatabaseIfModelChanges<MyDatabaseContext>());
System.Data.Entity.Database.SetInitializer<MyDatabaseContext>(new CreateDatabaseIfNotExists<MyDatabaseContext>());
System.Data.Entity.Database.SetInitializer<MyDatabaseContext>(new DropCreateDatabaseAlways<MyDatabaseContext>());
}
... which don't seem to work. Some give errors about not being about to get the model hash in EdmMetadata table.
How can I get EF4.1/Code First to create the DB structure in an already existing DB? (And in Azure...). Or do I have to script the DB from SQL Management studio, and run it against the destination DB?