When using Entity Framework to search the database, accents are ignored.

c# entity-framework non-ascii-characters

Question

I have a database table that contains names with accented characters. Like ä and so on.

I need to get all records using EF4 from a table that contains some substring regardless of accents.

So the following code:

myEntities.Items.Where(i => i.Name.Contains("a")); 

should return all items with a name containing a, but also all items containing ä, â and so on. Is this possible?

1
14
6/15/2011 12:01:44 PM

Accepted Answer

If you set an accent-insensitive collation order on the Name column then the queries should work as required.

14
6/15/2011 12:38:00 PM

Popular Answer

Setting an accent-insensitive collation will fix the problem.

You can change the collation for a column in SQL Server and Azure database with the next query.

ALTER TABLE TableName
ALTER COLUMN ColumnName NVARCHAR (100)
COLLATE SQL_LATIN1_GENERAL_CP1_CI_AI NOT NULL

SQL_LATIN1_GENERAL_CP1_CI_AI is the collation where LATIN1_GENERAL is English (United States), CP1 is code page 1252, CI is case-insensitive, and AI is accent-insensitive.



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow