EF core Migrations wrong latin SQL encoding

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

Question

I have a ASP.NET Core 1.0 project with EF7. When I add a migration with SQL command and latin characters, I get them replaced by "?" when updating database.

Let's see an example:

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

    protected override void Down(MigrationBuilder migrationBuilder)
    {
    }
}

And this is the script I get from that migration:

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');

As you can see, all latin characters have been replaced by "?"

1
3
2/16/2016 5:05:37 PM

Accepted Answer

I had the same problem and I solved it by saving migration file again with UTF-8 encoding.

It seems that add-migration creates files with ANSI encoding.

So, open migration *.cs in notepad and then File->Save As and at the bottom set Encoding to UTF-8 then overwrite.

4
2/17/2016 10:51:04 AM

Popular Answer

It's a bug of RC1, as discussed here, and it's planned to be resolved in RC2



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow