Case-insensitive "contains" in Linq

That is totally not a LINQ issue.

Case sensitiivty on the generated SQL depends on the collation relevant for the table. Which in your case likely is case insensitive.

You would get the same result from any SQL you emit.


the easy way is to use ToLower() method

var lists = rec.Where(p => p.Name.ToLower().Contains(records.Name.ToLower())).ToList();

a better solution (based on this post: Case insensitive 'Contains(string)')

 var lists = rec.Where(p => 
             CultureInfo.CurrentCulture.CompareInfo.IndexOf
             (p.Name, records.Name, CompareOptions.IgnoreCase) >= 0).ToList();

Tags:

C#

Linq