3

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"

Community
  • 1
  • 1
sports
  • 7,851
  • 14
  • 72
  • 129
  • you're using sql server ? – Raphaël Althaus Jun 13 '14 at 06:28
  • Possible [duplicate](http://stackoverflow.com/questions/359827/ignoring-accented-letters-in-string-comparison) – enapi Jun 13 '14 at 07:00
  • @user1994514 I saw that question and is completly different... "Equals" is different from "Contains" – sports Jun 13 '14 at 15:45
  • @RaphaëlAlthaus Yes, i will add that to the question with an edit – sports Jun 13 '14 at 15:46
  • 1
    @sports so you'd rather look at this one, which is "linq to entities" friendly : look at the field collation part : http://stackoverflow.com/a/8144930/961526 – Raphaël Althaus Jun 13 '14 at 15:57
  • Thanks @RaphaëlAlthaus, so if someone comes to this post, the answer is to ALTER the column´s "COLLATION" to "SQL_Latin1_General_CP1_CI_AI", so that WHERE queries dont consider caps and accents. – sports Jun 13 '14 at 16:05
  • 2
    @sports well, I'd rather say "a collation ending with AI" (not everybody uses SQL_Latin1...), or CI_AI if you also want case insensitivity. (CI = case insensitive, AI = accent insensitive) – Raphaël Althaus Jun 13 '14 at 16:10

1 Answers1

2

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)

sports
  • 7,851
  • 14
  • 72
  • 129