SQL Server 2008中用于模糊查询的LINQ查询和Soundex是什么?

3
在SQL Server中,我们可以发出SQL语句来获取数据,例如:
select * from table where column like '%myword%'
select * from person where Soundex(LastName) =  Soundex('Ann')

如何使用LINQ查询语句匹配上述SQL?

2个回答

2
from t in table
where t.column.Contains("myword")
select t

在 .Net 4.0 中,您可以使用 SoundCode 函数,可能像这样:
from p in person
where SqlFunctions.SoundCode(p.LastName) == SqlFunctions.SoundCode('Ann')
select p

0

谢谢。根据信息所说:您不能直接调用此函数。此函数只能出现在LINQ to Entities查询中。我使用实体框架作为数据访问层。那么如何在INQ to Entities查询中编写它呢?假设q是EntityQuery<person>,查询应该像这样:q = q.Where(p => p.LastName.Soundex() == someword);?但我无法这样做。 - KentZhou
如果我是你,我可能会创建一个存储过程来完成这个任务。我不知道其他的方法。 - John Boker

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接