2016-06-10 39 views
3

我想在ASP.NET MVC Core 1.0项目中运行SQL脚本。这里的答案:Can we run sql script using code first migrations? 几乎解释正是我想要做的,只是这一行:如何在.NET Core 1.0中使用实体框架运行SQL脚本?

Sql(File.ReadAllText(sqlFile)); 

它吠叫,并说“这个名字‘SQL’不会在当前的背景下存在”。 我确定在.NET Core 1.0中必须有一种方法。 我刚刚开始使用.NET Core 1.0,所以它可能很简单,我错过了。

回答

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

    protected override void Down(MigrationBuilder migrationBuilder) 
    { 
    } 
} 
+2

甜。这很好。如果有其他人遇到它,我必须从脚本中删除“GO”语句才能正常工作。谢谢@Konstantin! –