如何在linq查询中使用%? [英] how to use like % in linq query ?
本文介绍了如何在linq查询中使用%?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
朋友们,
我在我的程序中使用mysql作为后端,wpf作为前端。在我想做的事情
hi friends,
i am using mysql as back end and wpf asa front end in my program. in that i want to do
select * from mcs_Hall where mcs_Hall_Name = "%j%";
查询。所以我试试这个编码
query. so i try this coding
string str = txt_Search.Text.Trim();
dataGrid1.DataContext = from re in MainWindow.mcsEntity.mcs_hall
where SqlMethods.Like(re.mcs_Hall_Name, "%j%")
select new
{
name = re.mcs_Hall_Name,
code = re.mcs_Hall_Code
};
但它会抛出此异常,...
LINQ to Entities无法识别方法'Boolean Like(System.String,System.String)'方法,并且此方法无法转换为商店表达式。
帮助我做到这一点。
but it throw this exception,...
LINQ to Entities does not recognize the method 'Boolean Like(System.String, System.String)' method, and this method cannot be translated into a store expression.
help me to do this.
推荐答案
http://stackoverflow.com/questions/2584598/linq-sqlmethods-喜欢 - 失败
这篇文章帮助我,
http://stackoverflow.com/questions/2584598/linq-sqlmethods-like-fails
this article help me,.
LIKE 'a%' => StartsWith("a")
LIKE '%a' => EndsWith("a")
LIKE '%a%' => Contains("a")
LIKE 'a%b' => StartsWith("a") && EndsWith("b")
LIKE '%a%b%' => StartsWith("a") && Contains("b")
现在我的代码是
now my code is
dataGrid1.DataContext = from re in MainWindow.mcsEntity.mcs_hall re.mcs_Hall_Name.Contains(txt_Search.Text.Trim())
非常感谢,。
thank u very much,.
通常,当我完全无能为力(大多数时候都是这种情况;))时,我会复制错误信息,看看是否有其他人有类似问题。
这个 [ ^ ]就是我做的在你的情况下。
和第一篇文章 [ ^ ]似乎很有希望。
Usually, when I am totally clueless (which is the case most of times ;)), I copy the error message and look if there are other people having a similar problem.
This [^]is what I did in your case.
And the very first article[^] seems to be promising.
这篇关于如何在linq查询中使用%?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文