EF 核心迁移错误的拉丁语 SQL 编码

本文关键字:拉丁语 SQL 编码 错误 核心 迁移 EF | 更新日期: 2023-09-27 18:35:03

我有一个使用 EF7 的 ASP.NET Core 1.0 项目。当我使用 SQL 命令和拉丁字符添加迁移时,我在更新数据库时将它们替换为"?"。

让我们看一个例子:

public partial class TestEncodingMigration : Migration
{
    protected override void Up(MigrationBuilder migrationBuilder)
    {
        migrationBuilder.Sql(@"some text with latin chars : á é í ñ");
    }
    protected override void Down(MigrationBuilder migrationBuilder)
    {
    }
}

这是我从该迁移中获得的脚本:

PM> dnx ef migrations script <some prev migration> -c MyDbContext
some text with accent: ? ? ? ?
;
GO
INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
VALUES (N'20160216162901_TestEncodingMigration', N'7.0.0-rc1-16348');

如您所见,所有拉丁字符都已替换为"?">

EF 核心迁移错误的拉丁语 SQL 编码

我遇到了同样的问题,我通过使用 UTF-8 编码再次保存迁移文件来解决它。

似乎添加迁移会使用 ANSI 编码创建文件。

因此,在记事本中打开迁移 *.cs,然后在文件>另存为,并在底部将编码设置为 UTF-8 然后覆盖。

这是 RC1 的一个错误,如此处所述,计划在 RC2 中解决