1

I need to find customer names that includes special Turkish characters. For example, Customer table is :

Id  Name     Surname
--------------------
1   Şağbüz   Akarca
2   Üleykö   Pancar

I want to find the record with Id 1 with this linq query :

context.Customers.Select(c => c.Name.Contains('Sagbuz'));

Another example :

context.Customers.Select(c => c.Name.Contains('Uleyko'));

This query is converted to this:

SELECT * FROM Customer WHERE Name LIKE N'Sagbuz'

That returns no row found. I couldn't find the way to achieve this.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Can
  • 659
  • 1
  • 7
  • 24
  • If you want to search for `Şağbüz` why are you using `Sagbuz`? – DavidG Dec 17 '17 at 19:43
  • 1
    Customer names are stored as nvarchar type in the database, but for my app, some people are searching names without turkish characters because they have an english keyboard layout (also they forget to use turkish letters) and they want to find the record with turkish letters. There is no issue with people who have turkish keyboard layout and searchs for word with correct letters. – Can Dec 17 '17 at 19:48
  • Are you able to change the database structure at all? – DavidG Dec 17 '17 at 19:50
  • I'm not able to – Can Dec 17 '17 at 19:54
  • Then you are limited to something like this https://stackoverflow.com/a/23212281/1663001 – DavidG Dec 17 '17 at 19:57
  • read about `kashidas` maybe this link will give you some [hints](http://www.c-sharpcorner.com/uploadfile/GemingLeader/working-with-strings-with-combining-characters/) – Monah Dec 17 '17 at 20:15

2 Answers2

1

It is not relevant with Linq to Entities. Probably, your database is configured as AS (Accent Sensitive). So, try to execute the below query;

SELECT * FROM Customer WHERE Name LIKE N'Sagbuz' COLLATE Latin1_General_CI_AI

The result will be returned for Şağbüz.

Also, be careful with that trying to change collation of the sql server might affect entire tables and records.

lucky
  • 12,734
  • 4
  • 24
  • 46
0

you should use "where" instead of "select":

context.Customers.Where(c => c.Name.Contains('Sagbuz'));
Mohammad
  • 537
  • 9
  • 6