Search code examples
linqentity-frameworklinq-to-entitiesfull-text-searchstring-search

Ignore acutes in LINQ when using "Contains"


Is it possible in pure LINQ-to-entities to use String's Contains() method without considering the acutes?

Example:

table Messages
---------------------------
  MessageId     Body
     1          Hello John how are you
     2          Hi Jóhn sup?
        ...

I want that this query:

var messages = db.Messages.Where(p => p.Body.Contains("John"));

Not only returns to me the first message, but the second message too.

If this is not the correct approach (Contains), which one is it?

I´m using SQL Server.

Also, there is a similar but different question here: Ignoring accented letters in string comparison

It is different because he is trying to compare two strings ("Equals", or "CompareTo"), ...while I´m trying to use "Contains"


Solution

  • The answer has been in the comments for a while. Here it is as an answer too:

    Alter the database collation to one that ends with "_AI" for making it accent insensitive (or "_CI_AI", for making it case insensitive too)