Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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));

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.

like image 235
Adrian Carr Avatar asked Jun 10 '16 13:06

Adrian Carr


People also ask

Can I use Entity Framework with .NET core?

To use Entity Framework 6, your project has to compile against . NET Framework, as Entity Framework 6 doesn't support . NET Core. If you need cross-platform features you will need to upgrade to Entity Framework Core.


1 Answers

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

    protected override void Down(MigrationBuilder migrationBuilder)
    {
    }
}
like image 86
Konstantin Tarkus Avatar answered Sep 27 '22 20:09

Konstantin Tarkus