1

LINQtoEFを使用してソリューションを開発しています。

私の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

それを行う方法を説明する素晴らしい記事があります: エンティティフレームワークの正規表現

于 2011-02-04T17:35:11.363 に答える