简体   繁体   English

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

[英]How to run sql script with Entity Framework in .NET Core 1.0?

I'd like to run sql scripts in an ASP.NET MVC Core 1.0 project. 我想在ASP.NET MVC Core 1.0项目中运行sql脚本。 The answer here: Can we run sql script using code first migrations? 答案在这里: 我们可以使用代码优先迁移来运行sql脚本吗? pretty much explains exactly what I want to do, except that for this line: 几乎可以解释我想要做什么,除了这一行:

Sql(File.ReadAllText(sqlFile));

it barks and says "The name 'Sql' does not exist in the current context" . 它吠叫并说“当前上下文中不存在名称'Sql'” I'm sure there must be a way in .NET Core 1.0. 我确信在.NET Core 1.0中必须有一种方法。 I'm just getting started with .NET Core 1.0, so it may be something simple that I'm missing. 我刚刚开始使用.NET Core 1.0,所以它可能是我想念的简单内容。

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

    protected override void Down(MigrationBuilder migrationBuilder)
    {
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM