Reputation: 1391
Im playing currently on visual studio 2012 asp.netmvc4 with simple membership. This will generate 5 tables after running.
My problem is how do i add additional tables? I tried by creating a new model and adding a DbSet on the context class but it will throw error saying dbo.model does not exist in the database. The table is not created.
Is there a standard way of adding a model that will generate a table without running db migrations command?
I even added this Database.SetInitializer(new HWMDContextInitializer()); on application start but the error is still there.
Upvotes: 2
Views: 7070
Reputation: 6808
If you want Entity Framework to drop and regenerate your database automatically whenever you change your model schema, use data migrations.
For more information refer to the documentation: http://msdn.microsoft.com/en-us/data/jj591621.aspx
Upvotes: 0
Reputation: 365
Go through this. It will give you the exact approach http://programmaticponderings.wordpress.com/2012/10/30/first-impressions-of-code-first-development-with-entity-framework-5-in-visual-studio-2012/
Upvotes: 0
Reputation: 184
Have you tried this?
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
Database.SetInitializer<YourContext>(new DropCreateDatabaseIfModelChanges<YourContext>());
Upvotes: 0