Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用LINQ到实体框架的复杂字符串匹配_C#_.net_Entity Framework_Linq To Entities_Wildcard - Fatal编程技术网

C# 使用LINQ到实体框架的复杂字符串匹配

C# 使用LINQ到实体框架的复杂字符串匹配,c#,.net,entity-framework,linq-to-entities,wildcard,C#,.net,Entity Framework,Linq To Entities,Wildcard,我们正在使用LINQ到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 que

我们正在使用LINQ到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;

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

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

有一篇很好的文章描述了如何做到这一点:
有一篇很好的文章介绍了如何做到这一点:

我认为可以用newString=toMatch替换代码的第一部分;是的,你是对的,我认为我的更明显是因为某些原因…:-)我认为可以用newString=toMatch替换代码的第一部分;是的,你是对的,我认为我的更明显是因为某些原因…:-)上面好像有一份破损的文章,上面好像有一份破损的文章。