Linq to Entities - 查询以检查输入中 "n" 个字符的匹配

Linq to Entities - Query to check for match on "n" number of characters from input

我想根据用户输入的字符返回一组结果。

我创建了以下查询,它在 LINQpad4 中执行我想要的操作

LinqPad

var PostCodes = (from OA in OrganisationAddresses
               join OV in OpportunityVersions on OA.ID equals OV.LocationID
               where OA.CurrentVersion.PostCode.Contains("LH") 
               select OV.ID).ToList();

PostCodes.Dump();

用户输入字符串"LH",我返回13个结果

现在,当我在我的生产环境中放置一个非常相似的查询时,如果我输入 "LH",我会得到零结果。它只有 returns 在输入完整字符串时匹配,例如 "LH1 1HP"

生产

Builder = Builder.And(o => 
(from OA in Context.OrganisationAddresses
 join OV in Context.OpportunityVersions on OA.ID equals OV.LocationID
 where Options.PostCode.Contains(OA.CurrentVersion.PostCode) 
 && OV.ID == o.CurrentVersionID select OV.ID).Any());

我正在使用 SQLServer2012 和 LINQ to Entities。我想知道是什么原因造成的,以及如何解决它。

谢谢

你似乎误换了一些代码

Builder = Builder.And(o => 
(from OA in Context.OrganisationAddresses
 join OV in Context.OpportunityVersions on OA.ID equals OV.LocationID
 where OA.CurrentVersion.PostCode.Contains(Options.PostCode) // fix in this string
 && OV.ID == o.CurrentVersionID select OV.ID).Any());

并且您在产品中还有其他条件:

&& OV.ID == o.CurrentVersionID