18

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.

Community
  • 1
  • 1
MyNameIsJob
  • 2,508
  • 2
  • 17
  • 17

5 Answers5

31

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

MyNameIsJob
  • 2,508
  • 2
  • 17
  • 17
2

try working with linqpad

Dani
  • 14,639
  • 11
  • 62
  • 110
0

As Dani suggested, LinqPad is a great tool for this. And, even though it will not allow you to "step into" Linq queries, you can use an extended method offered in LinqPad named Dump() that will show you the value of IEnumerable or IQueryable objects as you progress through your query. It is extremely useful.

Randy Minder
  • 47,200
  • 49
  • 204
  • 358
0

Is this query being run against the database (LINQ to EF) or against objects already in memory (LINQ to objects). I'm guessing that it is LINQ to objects based on a comment you made on another answer, in which case you should be able to set a breakpoint in the lambda expression.

tster
  • 17,883
  • 5
  • 53
  • 72
-1

Why don't you do a selection on that ToLowerInvariant() to see what it is returning.

tster
  • 17,883
  • 5
  • 53
  • 72