Reputation: 709
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.
Upvotes: 14
Views: 8711
Reputation: 173
If you want to use placeholders then your code should look like
this.someQuery = this.someQuery.Where("field" + ".ToLower().Contains(@0.ToLower())", strValue);
Upvotes: 1
Reputation: 14777
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?
Upvotes: 18