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

前端之家收集整理的这篇文章主要介绍了linq-to-sql – 如何在linq中调用UDF到sql查询?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何将以下sql语句转换为 linq查询
select ID,Price,dbo.fGetText(DescriptionID,defaultLanguage,currentUserLanguage) 
from Products

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

不能选择往返数据库服务器.应该只有一个查询,检索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.

猜你在找的MsSQL相关文章