小编ted*_*e24的帖子

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

我有一个带有 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)
    {
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我从那次迁移中得到的脚本:

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');
Run Code Online (Sandbox Code Playgroud)

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

c# entity-framework-core asp.net-core-1.0

3
推荐指数
1
解决办法
1681
查看次数