如何在.NET Core 1.0中使用Entity Framework运行sql脚本?

Adr*_*arr 5 .net c# sql entity-framework

我想在ASP.NET MVC Core 1.0项目中运行sql脚本.答案在这里:我们可以使用代码优先迁移来运行sql脚本吗? 几乎可以解释我想要做什么,除了这一行:

Sql(File.ReadAllText(sqlFile));
Run Code Online (Sandbox Code Playgroud)

它吠叫并说"当前上下文中不存在名称'Sql'".我确信在.NET Core 1.0中必须有一种方法.我刚刚开始使用.NET Core 1.0,所以它可能是我想念的简单内容.

Kon*_*kus 11

private class SomeMigration : Migration
{
    protected override void Up(MigrationBuilder migrationBuilder)
    {
        migrationBuilder.Sql(File.ReadAllText(sqlFile));
    }

    protected override void Down(MigrationBuilder migrationBuilder)
    {
    }
}
Run Code Online (Sandbox Code Playgroud)

  • 甜.这很有效.如果有其他人遇到它,我必须从我的脚本中删除"GO"语句才能工作.谢谢@Konstantin! (2认同)