linq包含查询 [英] linq contains query
本文介绍了linq包含查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好
我使用linq包含查询,但它不会搜索不敏感的??
我应该怎么做才能搜索大写字母和小写字母????:confused:
hello
i use linq contains query ,but it does not search insensitive??
what can i do for searching capital and small character???:confused:
推荐答案
看起来像您在LINQ中使用包含一样,条款.
LINQ to SQL会将Contains()转换为通常不区分大小写的SQL LIKE语句.
试试:
选项1:
Looks like you are using Contains in your LINQ where clause.
LINQ to SQL will translate a Contains() to a SQL LIKE statement which is not case sensitive in general.
Try:
OPTION 1:
s = From row In context.Table Where String.Compare(row.Name, "test", StringComparison.CurrentCulture) = 0
或
选项2:
如果要使用Contains子句,最好的方法是创建自己的比较器.看这里:
可枚举.包含 [
OR
OPTION 2:
If you want to use the Contains clause then, best way would be to create your own comparer. Look here:
Enumerable.Contains[^]
var查询=来自context中的行. Data.Linq.SqlClient.SqlMethods.Like(row.Name,%test%")
var Query = From row In context.Table Where System.Data.Linq.SqlClient.SqlMethods.Like(row.Name,"%test%")
更改数据库中的排序规则或编写如下内容:
tblUsers
.where(u => u.userName.Contains("Test")).AsEnumerable()
.where(u => u.userName.IndexOf("Test",StringComparison.CurrentCulture)!= -1)
Change the Collation in the database or write something like this:
tblUsers
.Where (u => u.userName.Contains("Test")).AsEnumerable()
.Where (u => u.userName.IndexOf("Test", StringComparison.CurrentCulture) != -1)
这篇关于linq包含查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文