您的位置:知识库 » 数据库

Linq To Sql进阶系列(五)Store Procedure篇

作者: Tom Song  来源: 博客园  发布时间: 2008-09-27 11:59  阅读: 9833 次  推荐: 0   原文链接   [收藏]  

系列文章导航:

Linq To Sql进阶系列(一)从映射讲起

Linq To Sql进阶系列(二)M:M关系

Linq To Sql进阶系列(三)CUD和Log

Linq To Sql进阶系列(四)User Define Function篇

Linq To Sql进阶系列(五)Store Procedure篇

Linq To Sql进阶系列(六)用object的动态查询与保存log篇

Linq To Sql进阶系列(七)动态查询续及CLR与SQL在某些细节上的差别


Store Procedure,存储过程。也是被别人写过的东西。我习惯性先看别人都写了点啥,然后才开始想看看自己还要写点啥。那就先谈谈它与udf的区别吧。

Linq To Sql进阶系列(四)User Define Function篇 中,我们提到了两者的差别。比如Store Procedure支持多个rowset的,而udf不行。他们还有一些其他的差别。Store Procedure只能返回整型,而udf可以是其他类型,比如char等,除个别类型外,比如imager类型,是不可以做为udf的返回类型的。Store Procedure支持Out Parameter而udf没有。

1, SingleResultSet
我们先来看这个sprocs.

CREATE PROCEDURE [dbo].[Customers By City]
    
-- Add the parameters for the stored procedure here
    (@param1 NVARCHAR(20))
AS
BEGIN
    
-- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;
    
SELECT CustomerID, ContactName, CompanyName, City from Customers as c where
 c.City
=@param1
END

其生成的code如下。

        [Function(Name="dbo.[Customers By City]")]
        
public ISingleResult<Customers_By_CityResult> Customers_By_City([Parameter(DbType=
"
NVarChar(20)")] string param1)
        
{
            IExecuteResult result 
= this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), param1);
            
return ((ISingleResult<Customers_By_CityResult>)(result.ReturnValue));
        }

这里Customers_By_CityResult是这个sprocs的影射类。但你可以在OR Designer里调整。如图,

0
0

数据库热门文章

    数据库最新文章

      最新新闻

        热门新闻