0

I always thought a Linq clause was case sensitive, but I have this code which returns results with a lower case search string, but the records have upper case

           List<RailUnitLocation> locations = db.RailUnitLocations.Where(r => r.Division == division).ToList();

              List<string> serialNumbers = new List<string>();

              foreach (RailUnitLocation location in locations)
              {
                    serialNumbers.Add(location.SerialNumber);
               }
mjwills
  • 23,389
  • 6
  • 40
  • 63
Patrick Goode
  • 1,412
  • 5
  • 20
  • 35
  • 7
    It generates SQL and runs it against the database. It will be as case sensitive as your database is (if you ran the SQL directly). – mjwills Aug 01 '19 at 13:56
  • @mjwills Ok that makes sense. If you want, I'll mark that as an answer. RailUnitLocations is a table with a column 'division' which has upper case 'CHICAGO' but I'm searching lower case chicago and it returns results – Patrick Goode Aug 01 '19 at 14:01
  • 1
    Most DBs are setup to be case insensitive. If you need a case sensitive filter you can first do the filter normally just to reduce the results, then a `AsEnumerable` and then do the filter again to get it to do a case sensitive filter as it will now be doing it in memory where you can tell it to be sensitive or not. – juharr Aug 01 '19 at 14:04

0 Answers0