EF6 DbMigrations.Sql方法等效于Entity Framework Core

Rez*_*eza 3 entity-framework asp.net-core

有使用SQL命令执行SQL语句的EF Core等效方法吗?例如。我想通过内核中的迁移来“播种”我的数据库,以在UP方法中使用一些默认值:

    public partial class PopulateGenresTable : Migration
{
    protected override void Up(MigrationBuilder migrationBuilder)
    {
        Sql("INSERT INTO Genres (Id, Name) VALUES (1, 'Jazz')");
    }

    protected override void Down(MigrationBuilder migrationBuilder)
    {

    }
}
Run Code Online (Sandbox Code Playgroud)

Rez*_*eza 5

找到了我自己的答案。在Core中,我必须使用migrationBuilder方法

        protected override void Up(MigrationBuilder migrationBuilder)
    {
        migrationBuilder.Sql("INSERT INTO Genres (Name) VALUES ('Jazz')");
    }
Run Code Online (Sandbox Code Playgroud)