如何在.NET Core 1.0中使用Entity Framework运行SQL脚本? [英] How to run sql script with Entity Framework in .NET Core 1.0?

查看:97
本文介绍了如何在.NET Core 1.0中使用Entity Framework运行SQL脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'd like to run sql scripts in an ASP.NET MVC Core 1.0 project. The answer here: Can we run sql script using code first migrations? pretty much explains exactly what I want to do, except that for this line:

Sql(File.ReadAllText(sqlFile));

它吠叫说名称'Sql'在当前上下文中不存在
我确定.NET Core 1.0中一定有一种方法。
我刚刚开始使用.NET Core 1.0,因此可能缺少一些简单的东西。

it barks and says "The name 'Sql' does not exist in the current context". I'm sure there must be a way in .NET Core 1.0. I'm just getting started with .NET Core 1.0, so it may be something simple that I'm missing.

推荐答案

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

    protected override void Down(MigrationBuilder migrationBuilder)
    {
    }
}

这篇关于如何在.NET Core 1.0中使用Entity Framework运行SQL脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆