views:

1080

answers:

1

How can I ignore accents (like ´, `, ~) in queries made to a SQL Server database using LINQ to SQL?

UPDATE:
Still haven't figured out how to do it in LINQ (or even if it's possible) but I managed to change the database to solve this issue. Just had to change the collation on the fields I wanted to search on. The collation I had was:

SQL_Latin1_General_CP1_CI_AS

The CI stans for "*C*ase *I*nsensitive" and AS for "*A*ccent *S*ensitive". Just had to change the AS to AI to make it "*A*ccent *I*nsensitive". The SQL statement is this:

ALTER TABLE table_name ALTER COLUMN column_name column_type COLLATE collation_type

+1  A: 

In SQL queries (Sql Server 2000+, as I recall), you do this by doing something like select MyString, MyId from MyTable where MyString collate Latin1_General_CI_AI ='aaaa'.

I'm not sure if this is possible in Linq, but someone more cozy with Linq can probably translate.

If you are ok with sorting and select/where queries ALWAYS ignoring accents, you can alter the table to specify the same collation on the field(s) with which you are concerned.

JasonTrue
Here's a sample, I probably picked this up from one of my web searches but can't remember the URL. SELECT *FROM nametableWHERE name = 'abbee' COLLATE Latin1_General_CI_AI -- Case-Insensitive, Accent-Insensitive comparisonAND <anotherColumn> LIKE '%Accent%' COLLATE Latin1_General_CI_AS -- Case-Insensitive, Accent-Sensitive comparisonORDER BY <yetAnotherColumn> DESC COLLATE Latin1_General_CS_AS -- Case-Sensitive, Accent-Sensitive sort order
Raj