The following are the steps that I took to transfer code from the first project using the special implementation of IDatabaseInitializer, which reset the database during each session to install a non-volatile database.
First, copy the schema generated by the Entity Framework in your dev. By executing the following code and placing the output in an accessible place (for example: a file on the desktop, source code in a browser, etc.). context - an instance of your class that inherits from DbContext:
((IObjectContextAdapter)context).ObjectContext.CreateDatabaseScript()
Second, save the string returned from this call in the SQL file. Be sure to remove the command that creates the Entity Framework metadata table. This command should resemble the following:
create table [dbo].[EdmMetadata] ( [Id] [int] not null identity, [ModelHash] [nvarchar](max) null, primary key ([Id]) );
Then delete the code that seeds the database. I used AppSetting so that I can easily switch this code usage after deployment without the need for recompilation and deployment.
if (ConfigurationManager.AppSettings["Mode"] == "Dev") { Database.SetInitializer<PonosContext>(new PonosInitializer()); new MyContext().Database.Initialize(true); }
Directly outside the scope of this statement, you still need to initialize the database, but be sure to pass false so that initialization only occurs if the database has not been initialized.
new MyContext().Database.Initialize(false);
Finally, run your SQL installation query in an empty database to create tables with corresponding fields.
If you deploy and run the application, it should connect to the database and work as usual with any data loaded into an external script. I have successfully tested this method with custom membership and role providers.