You have to create empty migration and then in Up method you can write your SQL query.
- Create Empty Migration by running Add-Migration command in Package
Manager Console.
- Add the SQL function in Up method like the following way.
public partial class your_migration_name : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql(@"<YourQuery>");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql(@"Drop <YourQuery>");
}
}
- Run
Update-Database in Package Manager Console.
migrationBuilder.Sqlmethod is your friend. For more info, see Migrations and API Reference.