以下 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/