tags:

views:

95

answers:

3

This code is case sensitive, how to make it case insensitive?

public IQueryable<FACILITY_ITEM> GetFacilityItemRootByDescription(string description)
{
    return this.ObjectContext.FACILITY_ITEM.Where(fi => fi.DESCRIPTION.Contains(description));
}
+2  A: 
fi => fi.DESCRIPTION.toLower().Contains(description.ToLower())
Nealv
Thanks Nealv, now it's working.
Jeaffrey Gilbert
there might be a more elegant solution, but this is logical and works anyhow. I will look for the elegant solution later
Nealv
+1  A: 

Use extension method Contains from System.Linq, which has Comparer:

public IQueryable<FACILITY_ITEM> GetFacilityItemRootByDescription(string description)
{
    return this.ObjectContext.FACILITY_ITEM.Where(
        fi => fi.DESCRIPTION.Contains(
            description,
            StringComparer.OrdinalIgnoreCase));
}
Pavel Belousov
In my case it is error, Delegate '<System.Func<MyProject.Web.FACILITY_ITEM,int,bool>' does not take 1 arguments. Nealv's is right, but thanks.
Jeaffrey Gilbert
This will not work as it will act on individual characters in the string, not substrings.
Jeff M
A: 

Assuming we're working with strings here, here's another "elegant" solution using IndexOf().

public IQueryable<FACILITY_ITEM> GetFacilityItemRootByDescription(string description)
{
    return this.ObjectContext.FACILITY_ITEM.Where(fi => fi.DESCRIPTION.IndexOf(description, StringComparison.InvariantCultureIgnoreCase) != -1);
}
Jeff M
s/elegant/magical :)
Earlz