Friday, October 21, 2016

Performing Entity Framework Code First Migrations step-by-step

If you need to perform Entity Framework Code First Migrations, you will probably end up following this article: https://msdn.microsoft.com/en-us/data/jj591621(v=vs.113).aspx

However, as with most Microsoft articles, the documentation leaves a lot to be desired...

Therefore, I will provide a more thorough step-by-step walk through on just how to do this!


  1. After opening up the Package Manager Console, you will want to make sure you choose the "Default project" before running the command to "Enable-Migrations"


  2. This will then create a Configuration.cs file shown as follows:



  3. Next, when you run "Add-Migration <MyMigrationName>", then you will get the following message along with the migration file added to your project:



  4. You can then run the "Update-Database" command if you want to run the command directly against the database. However, if you are like most developers and want to know what the database script looks like before it is applied to the database, you can instead run the "Update-Database -Script" command which will generate a SQL script instead which you can then save off for reference!


  5. For every change each developer makes to the Entity Framework Code First models, you simply repeat the "Add-Migration" and "Update-Database" steps respectively (corresponding to the Code First model changes that were made) and you can ignore the "Enable-Migrations" command.  That is all there really is to it! :-) 

1 comment:


  1. Online Auctions Texas provide a dynamic platform for buyers and sellers to engage in seamless transactions from the comfort of their homes. These virtual marketplaces bridge the gap between local vendors and a broader audience, allowing for a diverse array of products to be showcased.

    Whether it’s antiques, collectibles, real estate, or automobiles, online auctions in Texas offer a unique opportunity to discover valuable items that might not be available through traditional retail channels. Participants can place bids at their convenience, monitor ongoing auctions in real time, and enjoy competitive pricing as they engage in the excitement of the bidding process.

    ReplyDelete