11.16.2012

Set Up Code First Migrations for EF in ASP.NET MVC 4

First open Package Manager Console: Tools > Library Package Manager > Package Manager Console

1.  Go to the project, either the Web Application or if a separate project for Model, then enable the migration as follows:
PM> Enable-Migrations -ContextTypeName ProductCoC.Model.DataContext
This creates a Migration folder within the project root and creates the initial creation classes as well as the Configuration.cs.  Open Configuration.cs and add your seed.

2.  Initialize
PM> Add-Migration Initial
3.  Now, let's update the database:
PM> update-database
4.  If adding a property to the model classes, change the model class then do an add as follows, any arbitrary name will do:
PM> add-migration AddSoldToPartyAndShipToParty
5.  Now do a database update:
PM> update-database

No comments:

Post a Comment