Ste*_*yes 10 sql soundex linq-to-sql
I have done a little bit of research on this and looked through a few articles both here on StackOverflow as well as some blog posts, but haven't found an exact answer. I also read that it is possible to do it using the 4.0 framework, but have yet to find any supporting evidence.
So my question, is it possible to perform SOUNDEX via a LINQ to SQL Query?
Dev*_*ave 21
您可以使用假UDF在数据库中执行此操作; 在部分类中,向数据上下文添加方法:
[DbFunction(Name = "SoundEx", IsComposable = true)]
public string SoundsLike(string input)
{
throw new NotImplementedException();
}
Run Code Online (Sandbox Code Playgroud)
您可以使用如下表达式:
x => db.SoundsLike(x.QuoteValue) == db.SoundsLike("text")
Run Code Online (Sandbox Code Playgroud)
最初的想法来自: 从Linq到Sql的随机行
添加如下udf
CREATE FUNCTION [dbo].[udfSoundex]
(
@Soundex nvarchar(100)
)
RETURNS nvarchar(100)
AS
BEGIN
RETURN Soundex(@Soundex)
END
Run Code Online (Sandbox Code Playgroud)
只需将它从服务器资源管理器拖到visual studio dbml文件中的数据上下文中,并在代码中将其用作在datacontext类上公开的方法.
从 .net 4 开始,这也将起作用:
from p in mytable
where SqlFunctions.SoundCode(p.MyRow) == SqlFunctions.SoundCode("test")
select p
Run Code Online (Sandbox Code Playgroud)
更多信息:http : //msdn.microsoft.com/en-us/library/system.data.objects.sqlclient.sqlfunctions.soundcode.aspx
| 归档时间: |
|
| 查看次数: |
6044 次 |
| 最近记录: |