LINQ to Entity Frameworkとの複雑な文字列のマッチング
-
05-07-2019 - |
質問
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;
" *"を試しましたワイルドカードと正規表現ソリューションとして、無駄に-他のオプションはありますか?
解決
Equals を使用する代わりに、 Contains を使用してみます。これは、 Contains
var results = from a in mycontainer.users
where a.fullname.Contains(newString)
select a.fullname;
他のヒント
その方法を説明した素晴らしい記事があります: エンティティフレームワークの正規表現
所属していません StackOverflow