Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Code First issue with seeding data in Cyrillic

I am using the seed method to populate the database. Some of the objects have properties in cyrillic. Example:

context.Wines.AddOrUpdate(new Wine()
       {
           Id = 1,
           Name = "Шардоне",
           etc........................................

The objects are properly created in the database, however when I check the database in MS SQL management studio instead of the wine's name being "Шардоне", it is displayed as "Øàðäîíå".

Strangely, when I create the wine in my Startup class like this:

var db = new WineSystemDbContext();
var ShardoneWine = new Wine { Name = "Шардоне};
db.Wines.Add(ShardoneWine);

everything is displayed properly in cyrillic in the database.

Do you have an idea what may cause this?

like image 250
mega_n00b Avatar asked Jan 05 '16 22:01

mega_n00b


1 Answers

You can specify the charset of your connectin in connection string. Just add this part to your connection:

charset=UTF8;

If no results you can try to change char-set of Configuration.cs file. There are two ways to do that.

  1. Close Configuration.cs in Visual Studio editor, then right-click on that file in Solution Explorer and select "Open With..." -> "CSharp Editor with Encoding" and from a list choose "Unicode (UTF-8 with signature) - Codepage 65001" option (try other codepage if this one will show you some 'Chinese' symbols). Now fix your cyrilic chapters and save Configuration.cs file.
  2. Select "File" -> "Advanced Save Options" and save file with the method that seed data with the UTF-8 encoding.

You can also have problems if you are using ntext column type.

like image 156
Vadim Martynov Avatar answered Sep 19 '22 10:09

Vadim Martynov