Creating database scripts from Entity Framework Code First Migrations

We can easily create a T-SQL script from a database built with Code First Migrations by entering the following command in the Package Manager console:

Update-Database -Script -SourceMigration:$InitialDatabase

This command creates a T-SQL script for all migrations and opens it in Visual Studio. Unfortunately, scripts aren't created for the database seeding as this isn't part of Entity Framework migrations, so this has to be scripted separately.

Once we have these scripts, system administrators or database administrators can easily use them to build databases for our application environments without Code First Migrations. Once deployed, we can create more scripts to move to the ...

Get Learning Microsoft Azure now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.