65.9K
CodeProject is changing. Read more.
Home

LINQ Query Case Sensitivity

starIconstarIconstarIcon
emptyStarIcon
starIcon
emptyStarIcon

3.40/5 (4 votes)

Feb 4, 2012

CPOL
viewsIcon

30241

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".

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.

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