Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EF Query using .Contains() and .ToLowerInvariant() Results in no matches when match is found at the end of a string

Is it possible to step into a linq query? I have a linq to entity framework 4 query in it's simplest form:

List = List.Where(f => f.Value.ToString().ToLowerInvariant().Contains(filter.ToLowerInvariant()));

It's a query against an Entity Framework DbContext and I'm having trouble seeing why it works for something like:

List searching for 001 yields no results against the following list

  1. Test001
  2. Test002
  3. Test003
  4. Test004

However any other search yields results (Such as t00 or Test)

Update

Basically I'm looking for why a query such as the above wouldn't return a result when I'm using a contains and the value matches the end of a string vs just the middle or begining. It's really confusing.

OK, it appears to have something to do with ToLowerInvariant() - when I removed that method it works just fine.

like image 688
MyNameIsJob Avatar asked Dec 27 '10 21:12

MyNameIsJob


1 Answers

It appears that ToLowerInvariant() produces the error. ToLower() works just fine.

like image 120
MyNameIsJob Avatar answered Oct 03 '22 16:10

MyNameIsJob