Categories
chinese-locale entity-framework linq sql sql-server

How can I get rid of having to prefix a WHERE query with ‘N’ for Unicode strings?

When searching for a string in our database where the column is of type nvarchar, specifying the ‘N’ prefix in the query nets some results. Leaving it out does not. I am trying the search for a Simplified Chinese string in a database that previously did not store any Chinese strings yet.

The EntityFramework application that uses the database, correctly retrieves the strings and the LINQ queries also work in the application. However, in SQL Server 2014 Management Studio, when I do a an SQL query for the string it does not show up unless I specify the ‘N’ prefix for unicode. (Even though the column is nvarchar type)

Works:

var text = from asd in Translations.TranslationStrings
where asd.Text == "嗄法吖无上几"
select asd;
MessageBox.Show(text.FirstOrDefault().Text);

Does not work:

SELECT *
FROM TranslationStrings
where Text="嗄法吖无上几"

If I prefix the Chinese characters with ‘N’ it works.

Works:

SELECT *
FROM TranslationStrings
where Text = N'嗄法吖无上几'

Please excuse the Chinese characters, I just typed something random. My question is, is there something I can do to not have to include the ‘N’ prefix when doing a query?

Thank you very much!