简体   繁体   中英

How do I use Hebrew characters with Entity Framework and SQL Server 2008 R2?

I have a web service that takes XML, parses it to create EF objects, then persists those objects to the database (via the EF context).

This all works fine with normal English characters, but now someone wants to post Hebrew, but when he does, the value in the database is just ????.

The database column uses nvarchar() , and if I execute the following SQL in SSMS, it works just fine...

update customers 
set Salutation = N'אבגד' 
where LgID = 3 and VcID = 1

select * 
from Customers 
where LgID = 3 and VcID = 1

I can see the Hebrew correctly.

I have checked the data coming into the web service, and the value in the EF entity's property is correct, but when EF persists it to the database, it converts it to ????.

Anyone able to tell me what I need to do to allow Hebrew (as well as English) to be persisted? Thanks.

Thought I'd better post this as a separate answer instead of a comment, in case anyone else comes looking for it.

Turned out that the database was set up correctly, but I had forgotten to update the EF model to reflect the changes (ie changing varchar to nvarchar). Once I updated the model, it worked fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM