Entity framework migrations update your database according your model

Entity framework migrations are easy to use ( maybe to easy ). In fact there are three command you need to know:

  • Enable-Migrations
  • Add-Migration
  • Update-Database

Enable migrations parameters

Enable migrations have not a lot of parameters:


This is a important parameter, this parameter indicates if automatic migrations will be created. Automatic migrations compare you models with the existing database and build a migration. Works perfect if everything is perfect, if not, and you have to tweak a litle somewhere this can be a pain in your....


Entity framework search for the DataContext file in the standard project, which in most cases is the UI project. So he will not find it there and with this parameter you can indicate which project is your datalayer.


This is quite nice, it indicates that earlier build migrations can be overwritten.


Add-Migration creates a new migration script to update the database, in fact it has the commom parameters as Enable-Migration and some specific:


This will just build a new migration but doesn't scan for changes.


Most of the time the connection strings are saved in config files from the startup project, so thats's where this is for.

Update database

This has all of the common parameters of above plus a very nice one:


The script parameter indicates that the migration doesn't update the database but create a script-file ( T-SQL ) which you can tweak and run manually!</p




Saving your comment....

Naam is verplicht!
Email is verplicht!
Opmerking is verplicht!