When using Contains
with Dynamic Linq on Linq-to-objects, the search is case sensitive. I would like to be able to search case insensitive (like Linq-to-sql, cause SQL server does this by default).
Something like:
this.someQuery = this.someQuery.Where(field + ".Contains(@0, true)", strValue);
where true
means: caseinsensitive = true
, like one of the extensions of System.String.Contains
provides. Though i cannot use extensions to System.String
with dynamic Linq by default.
Use string. Equals(name, article.Name, StringComparison. OrdinalIgnoreCase) when you are sure that your database supports it. E.g. SQLite with a collate of NOCASE will ignore the option.
LINQ StartsWith , EndsWith , and Contains are case sensitive and return false if two same string s are of different cases, e.g., " STRING " and " string ".
It's possible to build up dynamic LINQ queries or queries with several conditional criteria. In fact there are several options for doing this, including the use of expression trees.
The Dynamic LINQ library exposes a set of extension methods on IQueryable corresponding to the standard LINQ methods at Queryable, and which accept strings in a special syntax instead of expression trees.
Can you just .ToLower() both sides of the comparison? Something like this:
this.someQuery = this.someQuery.Where(field.ToLower().Contains(strValue.ToLower()));
Or did I misunderstand what you're looking for?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With