I have read Case insensitive Contains(string), Why would Entity Framework not be able to use ToString() in a LINQ statement? and many other questions but I still can't figure out the right way.
string searchString = "max";
private db = new DbContext();
IQueryable<Person> persons = from m in db.Persons
select m;
if (null != persons)
{
//do what it should but marked as codesmell because of .ToStrong() with no culture
persons = persons.Where(s =>
s.person_name.ToLower().Contains(searchString.ToLower()));
//NotSupportedException
persons = persons.Where(s =>
cultureInfo.CompareInfo.IndexOf(s.person_name, searchString, CompareOptions.IgnoreCase) >= 0);
//NotSupportedException
persons = persons.Where(s =>
s.person_name.ToLower(CultureInfo.InvariantCulture).Contains(searchString.ToLower(CultureInfo.InvariantCulture)));
}
What is the right way to do a case insensitive string search in a db with LINQ?