Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EF core Migrations wrong latin SQL encoding

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 "?"

like image 215
tede24 Avatar asked Dec 05 '25 10:12

tede24


2 Answers

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.

like image 113
Peter Ožbot Avatar answered Dec 07 '25 22:12

Peter Ožbot


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

like image 29
tede24 Avatar answered Dec 08 '25 00:12

tede24



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!