StepUp StepUp - 8 months ago 76
C# Question

Result of adding data by EntityFramework in Cyrillic is exclamation marks. SQL Server

I have an web application where I just add some data by user inputs. However, when I test at real web server, I just see exclamation marks instead of "Привет".

using (DatabaseEntities context = new DatabaseEntities())
name = "Человек";
surname = "Привет";
Students student = new Students();
apho.ID = ID;
apho.Name = name;
apho.Surname = surname;
context.AddObject("Students", student);

The result is for Name: "???????" and for Surname is: "??????"

Any help would be greatly appreciated!


@mfanto is right. I use incorrect collation. A correct procedure is:

alter table Students
alter column
Surname Nvarchar(255)  COLLATE Cyrillic_General_CI_AS_KS not null

So my orders actions to see Russian letters in SQL Server through Entity Framework are:

  1. Change collation(see above code(sql query))
  2. create new ADO.NET Entity Data Model as collated columns from SQL table become in Entity Framework properties of classes are set to Unicode - true(I've seen these properties by clicking at properties in diagram)

That's it!:)