Add Sql Script through code first migration – Entity Framework

You can add scripts to code first migration.

First, make sure if any existing migration is pending. If so,

-open the package manager console window.

-Select the appropriate project

-Run “update-database” command (without quote)

Now, add the migration you want to put SQL into.

-Run “Add-Migration SQLIntoMigration”  (without quote)

A new MIgration file will be added with an empty body like this:

Now add the below code inside up() method.