2

EDIT:

Also like to know: what if; if i have a data that is not upper case? or have mixed of upper or lower case? how you will handle this?

i am trying to query my resultset

IQueryable<CategoryObject>  filteredCategories = _catRepo.GetAllEmployees();


 filteredCategories = filteredCategories.Where(c=> c.CategoryName.Contains("Blocks"));

However, i don't get any result becuase the CategoryName is For(Upper Case) in the database. I have no idea how to use contains to filter case insensitive string? I want basically if someone type like;

filteredCategories = filteredCategories.Where(c=> c.CategoryName.Contains("Blocks"));

OR

filteredCategories = filteredCategories.Where(c=> c.CategoryName.Contains("blocks"));

OR

filteredCategories = filteredCategories.Where(c=> c.CategoryName.Contains("blocKS"));

The result should be the same

4

3 回答 3

4

尝试

filteredCategories = categoriesList.Where(c=> c.CategoryName.ToUpper().Contains("BLOCKS"));

这将消除任何案例问题。

于 2013-10-27T14:06:33.830 回答
2

你也可以试试:

filteredCategories = categoriesList.Where(c=> c.CategoryName.IndexOf("blocks", StringComparison.OrdinalIgnoreCase) != -1);
于 2013-10-27T14:41:28.673 回答
1

第一种方式,如前所述 - 使用 ToUpper():

var filterString = "bLoCkS"
filteredCategories = categoriesList.Where(c=> c.CategoryName.ToUpper().Contains(filterString.ToUpper()));

另一种方法 - 在您的数据库(表、字段)中使用不区分大小写的排序规则(将 SQL Server 排序规则从区分大小写更改为不区分大小写?)。

于 2013-10-27T21:13:26.907 回答