Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / LINQ

LINQ Query Case Sensitivity

3.40/5 (4 votes)
4 Feb 2012CPOL 30.2K  
Case sensitive LINQ query

LINQ StartsWith, EndsWith, and Contains are case sensitive and return false if two same strings are of different cases, e.g., "STRING" and "string".


C#
string name = "STRING";
var employees = context.employees.Where(emp => emp.Name.Contains(name));

If in database employee name="string", no result will be returned. The most simple way is to convert both to lower case.


C#
string name = "STRING";
var employees = context.employees.Where(emp => emp.Name.ToLower().Contains(name.ToLower()));

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)