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));
}
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));
}
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));
}
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);
}