Linq To Sql进阶系列(四)User Define Function篇
[1] Linq To Sql进阶系列(四)User Define Function篇
[2] Linq To Sql进阶系列(四)User Define Function篇
[3] Linq To Sql进阶系列(四)User Define Function篇
[4] Linq To Sql进阶系列(四)User Define Function篇
[2] Linq To Sql进阶系列(四)User Define Function篇
[3] Linq To Sql进阶系列(四)User Define Function篇
[4] Linq To Sql进阶系列(四)User Define Function篇
系列文章导航:
Linq To Sql进阶系列(四)User Define Function篇
Linq To Sql进阶系列(五)Store Procedure篇
Linq To Sql进阶系列(六)用object的动态查询与保存log篇
Linq To Sql进阶系列(七)动态查询续及CLR与SQL在某些细节上的差别
User Define Function, 用户自定义函数,简称UDF. 关于sql server中的udf,请大家参考http://msdn.microsoft.com/msdnmag/issues/03/11/DataPoints/一文。本文主要阐述,在Linq To Sql中,如何使用UDF.
1,UDF 简介
UDF可以分为两中类型。一种为Scalar Valued Function,简称为SVF,是返回值类型的UDF. 另一种为Table Valued Function 简称为TVF,是返回一个table的UDF. 人们通常喜欢拿UDF和Store Procedure做比较。其实,他们各有千秋。UDF最多只能返回一个RowSet,而Store Procedure可以是多个。Store Procedure支持CUD操作,而UDF不支持。但是UDF在sql 中支持内联查询,这个又是Sprocs所不能及的。因此Linq To Sql 也支持UDF的内联查询。
2,SVF
看下面这个例子。返回某个类别产品最小的单元价格。
















用OR Designer(请参考OR工具介绍 )将其映射为Dbml。如下

IsComposable="true">


