1

I have a table, where I need to do a case insensitive search on a text field.

If I run this query in LinqPad directly on my database, it works as expected

Table.Where(tbl => tbl.Title.Contains("StringWithAnyCase"))
// also, adding in the same constraints I'm using in my repository works in LinqPad
// Table.Where(tbl => tbl.Title.Contains("StringWithAnyCase") && tbl.IsActive == true)

In my application, I've got a repository which exposes IQueryable objects which does some initial filtering and it looks like this

var dc = new MyDataContext();

public IQueryable<Table> GetAllTables()
{
    var ret = dc.Tables.Where(t => t.IsActive == true);
    return ret;
}

In the controller (its an MVC app) I use code like this in an attempt to mimic the LinqPad query:

var rpo = new RepositoryOfTable();
var tables = rpo.GetAllTables();
// for some reason, this does a CASE SENSITIVE search which is NOT what I want.
tables = tables.Where(tbl => tbl.Title.Contains("StringWithAnyCase");
return View(tables); 

The column is defined as an nvarchar(50) in SQL Server 2008.

** update **

I had a partial class (for one of my Entities from Linq-To-SQL) with an IQueryable property, but somehow returning an IQueryable from an EntitySet caused my later queries to behave in an IEnumerable (read Linq-To-Objects) way even though they were acting on IQueryable types.

Community
  • 1
  • 1
Nate
  • 30,286
  • 23
  • 113
  • 184
  • In between rpo.GetAllTables(); and tables.Where(...); you aren't doing anything else with it? – Ryan Rinaldi Apr 16 '10 at 16:40
  • There is another method (for additional filtering) but they are all `IQueryable` I'm NOT doing any converting ToList or IEnumerable.
    – Nate Apr 16 '10 at 19:12
  • **EDIT:** Think it is a duplicate question. Check out this SO [link](http://stackoverflow.com/questions/841226/case-insensitive-string-compare-in-linq-to-sql). HTH – Raja Apr 16 '10 at 16:54

0 Answers0