1

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);
   context.SaveChanges();                            
}

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

Any help would be greatly appreciated!

StepUp
  • 36,391
  • 15
  • 88
  • 148
  • 1
    Have you tried the solutions in these posts: https://stackoverflow.com/questions/21640405/entity-framework-cyrillic-displayed-as-question-marks and https://stackoverflow.com/questions/5889438/entity-framework-c-sharp-insert-data-russian-encoding-problems – mfanto Mar 20 '15 at 14:19

1 Answers1

2

@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
go

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

  1. Create Unicode fields(NVARCHAR)
  2. Change collation(see above code(sql query)). Maybe it is not necessary as I've created Unicode fields.
  3. 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!:)

StepUp
  • 36,391
  • 15
  • 88
  • 148