Linq是否有“差异"? [英] Does Linq have "Difference"?

查看:66
本文介绍了Linq是否有“差异"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Difference =>的sql语句 http://msdn.microsoft.com/en-us/library/ms188753. aspx

I have a sql statement that uses Difference => http://msdn.microsoft.com/en-us/library/ms188753.aspx

我在存储的proc中执行此操作,但是我想更改为LINQ.在LINQ中是否存在等于差异"?

I do this in a stored proc but i want to change to LINQ. Is there an equal to Difference in LINQ?

例如: WHERE (DIFFERENCE(C.LastName, ''' + @name + ''') >= 4

谢谢

推荐答案

The System.Data.Objects.SqlFunctions has (AFAIK) all the useful T-SQL functions like Difference, Soundex, Like, etc. These functions are translated in where clauses by Linq2Sql into their T-SQL equivalents.

编辑:糟糕,这是4.0.对于那个很抱歉.也就是说,您可以在数据库中创建一个用户定义的函数,然后将该函数添加到DBML文件中,然后像调用SqlMethods.Like(这就是我所想到的那样)一样调用它. 此处是MSDN文档.

Whoops, that's 4.0. Sorry about that. That said, to do so you can create a user-defined function in your database, and add that function to your DBML file and call it just like you would SqlMethods.Like (which is the one I was thinking of). Here's the MSDN docs on it.

基本上,您只是创建一个UDF,该UDF接受与DIFFERENCE相同的输入并返回相同的结果.该函数除了调用DIFFERENCE方法外什么也不做.然后,您可以在DBML中公开它,并在查询中使用您的函数.

Basically you just create a UDF that takes the same inputs as DIFFERENCE and returns the same results. That function does nothing but call the DIFFERENCE method. Then you expose that in your DBML, and use your function in your queries.

这篇关于Linq是否有“差异"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆