Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# LINQ problem with case sensitive

I have this:

var sortName = Request.Params["sortName"];
var query = Request.Params["query"];

Func<UsuarioEndereco, bool> whereClause = (uen => uen.GetPropValue<string>(sortName).Contains(query));

The "uen.GetPropValue<string>(sortName)" will be filled dynamically with the sortName the user typed in the page.

For example, if an user looks for a person named "Joe", the snippet will be:

(uen => uen.namePerson.Contains(Joe))

But, I'm having problems with LINQ Case-sensitive searches. If I type "Joe", I will something. On the other hand, If I type "joe", it bring nothing.

How can I make this "Contains(sortName)" works with Case-Insensitive?? I've tried some things with String.Comparer but it reports errors on build solution.

Thanks!!

like image 325
André Miranda Avatar asked May 05 '26 11:05

André Miranda


1 Answers

I believe the following will generate proper SQL:

 uen=>(uen.GetPropValue<string>(sortName)).ToLower().Contains(query.ToLower()))
like image 75
James Curran Avatar answered May 11 '26 00:05

James Curran



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!