LINQ是否支持这种LIKE过滤器 - '%Jo%Ja%'? [英] Does LINQ support this kind of LIKE filter - '%Jo%Ja%' ?
问题描述
我已经看到LINQ有 .contain , .startwith , .endwith , sqlmethod.like 但是如果我在中间使用通配符'%',它会将%视为另一个charector而不是通配符。
因此我们不能使用LINQ来过滤像普通SQL这样的数据,例如:LIKE%Jo% Ja%得到'先生' John Jam','John Lookjam'?
我说错了吗?或者只是我找不到路?
您必须使用SqlMethods,让你在你喜欢的值应该像更多的控制。
例如:来自ctx.customers中的c,其中SqlMethods.Like(c.Name,"%Jo%Ja%")选择c
I have seen that LINQ has .contain , .startwith , .endwith , sqlmethod.like but if I use wildcard '%' in the middle, it will treat % as another charector not a wildcard.
Therefore we can't use LINQ to filter data like normal SQL such as: LIKE %Jo%Ja% to get something like 'Mr. John Jam', 'John Lookjam' ?
Am I correct? or just I can't find the way?
You must to use SqlMethods which gives you more control in how you like value should look like.
For example:
from c in ctx.customers where SqlMethods.Like(c.Name, "%Jo%Ja%") select c
这篇关于LINQ是否支持这种LIKE过滤器 - '%Jo%Ja%'?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!