Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Entity framework 实体框架核心的等效EF6 DbMigrations.Sql方法_Entity Framework_Asp.net Core - Fatal编程技术网

Entity framework 实体框架核心的等效EF6 DbMigrations.Sql方法

Entity framework 实体框架核心的等效EF6 DbMigrations.Sql方法,entity-framework,asp.net-core,Entity Framework,Asp.net Core,是否存在使用SQL命令执行SQL语句的EF Core等效方法?例如,我想通过在core中进行迁移来“播种”我的db,以便在UP方法中插入一些默认值: public partial class PopulateGenresTable : Migration { protected override void Up(MigrationBuilder migrationBuilder) { Sql("INSERT INTO Genres (Id, Name) V

是否存在使用SQL命令执行SQL语句的EF Core等效方法?例如,我想通过在core中进行迁移来“播种”我的db,以便在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)
    {

    }
}

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

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