Click here to Skip to main content
15,888,351 members
Articles / LINQ
Tip/Trick

LINQ Query Case Sensitivity

Rate me:
Please Sign up or sign in to vote.
3.40/5 (4 votes)
4 Feb 2012CPOL 29.1K   2
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)


Written By
Kenya Kenya
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionMy 5 stars goes to relevance Pin
netfed15-Jan-16 0:15
netfed15-Jan-16 0:15 
This is a problem/question many have been pounding... so it is good to encounter an answer that also seems to be true
GeneralReason for my vote of 1 Not at all good candidate for articl... Pin
aamironline4-Feb-12 17:42
aamironline4-Feb-12 17:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.