如何在linq to sql查询中调用UDF? [英] How to call a UDF in a linq to sql query?

查看:95
本文介绍了如何在linq to sql查询中调用UDF?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下sql语句将如何转换为linq查询?

How would the following sql statement translate to a linq query?

select ID, 
       Price, 
       dbo.fGetText(DescriptionID, defaultLanguage, currentUserLanguage) 
from Products

UDF fGetText非常丰富,并在整个代码库中使用,因此需要将其封装(作为UDF或其他形式,也许是Linq表达式).

The UDF fGetText is quite substantial and used throughout the code base, so it needs to be encapsulated (as a UDF or otherwise, perhaps a Linq Expression).

到数据库服务器的额外往返行程不是一种选择.应该只有一个查询,可以检索3个字段.

Extra round trips to the database server are not a option. There should only be one query, retrieving 3 fields.

在此先感谢您的帮助.非常感谢.

Many thanks in advance for your help. It is greatly appreciated.

推荐答案

这是MSDN文章:

如何:内联调用用户定义的函数(LINQ to SQL)

同一页上的笔记:

尽管您可以调用用户定义的 内联函数, 包含在执行为 推迟执行直到 查询被执行.欲了解更多 有关信息,请参见LINQ简介. 查询.

Although you can call user-defined functions inline, functions that are included in a query whose execution is deferred are not executed until the query is executed. For more information, see Introduction to LINQ Queries.

当您调用相同的功能时 在查询之外,LINQ to SQL创建一个 从方法调用中进行简单查询 表达

When you call the same function outside a query, LINQ to SQL creates a simple query from the method call expression

也请看一下 查看全文

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