使用 EF Core 迁移更新现有列中的数据

Update data in existing column with EF Core Migration

我在 SQL 中的 table 有两个字段:Id 和 Status。看起来像这样

编号 |状态

1 | "Status1"

2 | "Status2"

我应该进行迁移以将这些状态值更改为我想要的值吗? 我怎样才能做到这一点?

I should make a migration that will change those status values into those that I want?

尝试将 SQL 语句添加到生成的迁移文件的 Up 方法中,如下所示

protected override void Up(MigrationBuilder migrationBuilder)
{
        migrationBuilder.Sql("UPDATE A SET AName = 'Jhon' WHERE Id=3");
}

更新多条记录,可参考以下代码

protected override void Up(MigrationBuilder migrationBuilder)
{
        migrationBuilder.Sql(
           "UPDATE A SET AName = CASE Id " +
                   "WHEN 1 THEN 'Shariy' " +
                   "WHEN 2 THEN 'Mary'" +
                   "ELSE AName END " +
                   "WHERE Id IN(1,2)");
}