0

I have the following code:

var items = db.Name.Where(x => x.Forename.IndexOf("john", StringComparison.OrdinalIgnoreCase) >= 0).Take(20);

Where db is a System.Data.Linq.DataContext.

This gives me the lovely error of:

The translation of String.IndexOf to SQL does not support versions with a StringComparison argument.

All I want to do is compare a string in a database to one entered by a user (in the example above hardcoded as "john") but not take into account the case sensitivity. I based the code off the following question Case insensitive 'Contains(string)'

Community
  • 1
  • 1
John
  • 487
  • 8
  • 16
  • 1
    Duplicate: http://stackoverflow.com/questions/2369022/using-contains-in-linq-to-sql – Mike Mooney Dec 21 '11 at 15:10
  • 1
    My guess is that the comparison will depend on the collation of the database. So if your database collation is not case sensitive, then the comparison won't be either. – Polyfun Dec 21 '11 at 15:23

1 Answers1

2

This might help:

string test="john";
db.tblUsers.Where (u =>u.Forename.ToLower().Contains((test.ToLower())).Take(20);
Arion
  • 31,011
  • 10
  • 70
  • 88