1

我们正在使用 LINQ to EF 来开发解决方案。

在我的 LINQ 查询中,我想

string toMatch = "Matt Cool";

newString = toMatch.Replace(" ", "% ") + "%"; 

// So here newString is 'Matt% Cool%'

/*Now in my datasource, there is no 'Matt Cool', there's 'Matthew Coolguy'.
I would like this query to return that result. 
I would expect this behavior with the 
wildcard. It doesn't work*/

var results = from a in mycontainer.users
              where a.fullname.equals(newString)
              select a.fullname;

我尝试将“*”作为通配符和正则表达式解决方案,但无济于事——还有其他选择吗?

4

2 回答 2

6

而不是使用Equals尝试使用Contains这应该带您的通配符,因为当您使用Contains时,内部 LINQ 使用LIKE

var results = from a in mycontainer.users
              where a.fullname.Contains(newString)
              select a.fullname;
于 2009-10-22T22:09:21.893 回答
-1

有一篇很棒的文章描述了如何做到这一点: Regex in entity framework

于 2011-02-04T17:35:11.363 回答