Can we run SQL script using code first migrations?

前端 未结 4 704
天命终不由人
天命终不由人 2020-12-04 12:23

Can we run sql script using code first migrations?

I am new to code first and if I want to save my changes to a SQL script file before update-datab

4条回答
  •  半阙折子戏
    2020-12-04 12:38

    For .NET Core and EF Core you can do something like this in migrations

    protected override void Up(MigrationBuilder migrationBuilder)
    {
       var schema = "starter_core";
       migrationBuilder.Sql($"INSERT INTO [{schema}].[Roles] ([Name]) VALUES ('transporter')");
    }
    

提交回复
热议问题