linq-to-sql - 如何在 linq to sql 查询中调用 UDF?

标签 linq-to-sql

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

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

UDF fGetText 非常重要,并在整个代码库中使用,因此需要对其进行封装(作为 UDF 或其他方式,可能是 Linq 表达式)。

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

非常感谢您的帮助。不胜感激。

最佳答案

这是 MSDN 文章:

How to: Call User-Defined Functions Inline (LINQ to SQL)

来自同一页面的注释:

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.

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



另外,看看这个 13 min screencast.

关于linq-to-sql - 如何在 linq to sql 查询中调用 UDF?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/500676/

相关文章:

c# - 强制linq执行内连接

c# - 尝试附加一个自动命名的数据库错误

c# - 业务逻辑层设计

c# - LINQ to SQL查询帮助(字符串包含字符串数组中的任意字符串)

c# - 尝试创建分部类时出错

c# - 当我将表名作为字符串时,如何创建 LINQ-to-SQL 语句?

sql-server - 表值参数 UdtTypeName

c# - 如何使用 linq 进行 LIKE 查询?

.net - 在 sql 查询中传递整数列表,最佳实践

c# - 我可以从使用 Linq to sql 的过程中接收返回值和结果集吗?