C# 使用LINQ到实体框架的复杂字符串匹配
我们正在使用LINQ到EF来开发解决方案 在我的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
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替换代码的第一部分;是的,你是对的,我认为我的更明显是因为某些原因…:-)上面好像有一份破损的文章,上面好像有一份破损的文章。