Code First issue with seeding data in Cyrillic

I use the seed method to populate the database. Some objects have properties in Cyrillic. Example:

context.Wines.AddOrUpdate(new Wine()
       {
           Id = 1,
           Name = "",
           etc........................................

Objects are properly created in the database, however, when I check the database in the MS SQL management studio, instead of the name of the wine, which is "Chardonnay", it appears as "Shared".

It is strange when I create wine in my Startup class as follows:

var db = new WineSystemDbContext();
var ShardoneWine = new Wine { Name = "};
db.Wines.Add(ShardoneWine);

everything is displayed correctly in cyrillic in the database.

Do you have any idea what might cause this?

+4
source share
5 answers

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

charset=UTF8;

, char -set Configuration.cs. .

  • Configuration.cs Visual Studio, " ..." → " CSharp ", " (UTF-8) ) - Codepage 65001" ( , "" ). Configuration.cs.
  • "" → " " , UTF-8.

, ntext.

+4

, , , nvarchar(x) , .

: varchar(100) , ??? - nvarchar(100) .

0

de N ( SQL Server, unicode), :

SELECT * FROM Wines WHERE someColumn = N'sometext'
0

!

( )

Configuration.cs , Seed Windows (, ).

" Configuration.cs Visual Studio, , " ... "- > " CSharp " " Unicode (UTF-8 ) - Codepage 65001 "( , " " ).

Notepad. , Update-Databse. .

".

0

The following helped me: Select "File" → "Advanced save options" and save the file using a method that will run data with UNICODE encoding (UTF-8 with signature) and line endings - Current settings.

0
source

Source: https://habr.com/ru/post/1622998/


All Articles