类似的存储过程会生成不同的返回类型 - 帮助! [英] Similar Stored Procedures generate different return types - HELP!

查看:86
本文介绍了类似的存储过程会生成不同的返回类型 - 帮助!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个几乎相同的存储过程 - 它们之间的唯一区别是一个接受两个参数并在其体内进行额外的更新。

I have two almost identical Stored Procedures - the only difference between them is that one takes two parameters and does an extra UPDATE within the body of it.

它们都结束了像这样:

IF
@@ ERROR
<> 0

BEGIN

 

RAISERROR
'无法插入新动作' 1 1

RAISERROR ('Could not insert new movement',1,1)

 

ROLLBACK
TRANSACTION

ROLLBACK TRANSACTION

 

返回
- 3

RETURN -3

 

END

END

 

COMMIT
TRANSACTION

COMMIT TRANSACTION

 

SET @NewMovementID
=
SCOPE_IDENTITY ()

SET @NewMovementID = SCOPE_IDENTITY()

- 返回新的MovementID

 

SELECT @NewMovementID

SELECT @NewMovementID

 

SET
NOCOUNT
OFF

SET NOCOUNT OFF

结束

然而,当我将它们拖到.dbml设计界面并进行构建时,方法签名因返回而异type - one返回一个int(这是我想要的)而另一个返回一个ISingleResult(我没有)

However, when I drag them onto the .dbml design surface and build, the method signatures differ by return type - one returns an int (which is what I want) while the other returns an ISingleResult (which I don't)

我尝试删除SPROC,删除并重新创建它,但是没有变化。

I've tried deleting the SPROC, dropping and recreating it, but no change.

想法,有人吗?谢谢。

 

 

推荐答案

Hello Edward,

 

感谢您在MSDN论坛上发帖。

据我所知,默认情况下linq to sql中的存储过程将返回
ISingleResult 类型。 以下示例表示返回客户行的存储过程并使用输入参数仅返回列出"伦敦"作为客户城市的行。该示例假定可枚举
CustomersByCityResult类。

As I know, The Stored Proc in linq to sql will return ISingleResult type by default.  The following example represents a stored procedure that returns rows of customers and uses an input parameter to return only those rows that list "London" as the customer city. The example assumes an enumerable CustomersByCityResult class.

CREATE PROCEDURE [dbo]。[按城市划分的客户]

   (@ param1 NVARCHAR(20))

AS

BEGIN

    - 添加SET NOCOUNT ON以防止额外的结果集从
    - 干扰SELECT语句。

    SET NOCOUNT ON;

    SELECT CustomerID,ContactName,CompanyName,来自客户的城市
        as c
其中c.City = @ param1

END

 

[功能(名称= "dbo.Customers By City" )]

public ISingleResult< CustomersByCityResult> CustomersByCity([Parameter(DbType = " NVarChar(20 )" )]
string param1)

{

   
IExecuteResult result =
这个 。ExecuteMethodCall( this         
((MethodInfo)( MethodInfo.GetCurrentMethod())),param1);

    IExecuteResult result = this.ExecuteMethodCall(this,         ((MethodInfo)(MethodInfo.GetCurrentMethod())), param1);

   
return ((ISingleResult< CustomersByCityResult>)(result.ReturnValue));

}

 

//调用存储过程。

// Call the stored procedure.

void ReturnRowset()

{

 

   
//如果你想返回“ Int”,请修改这些代码

    //If you want to return “Int”, please modify these codes

   
Northwnd db =
new Northwnd( @" c:\ northwnd.mdf" );

    Northwnd db = new Northwnd(@"c:\northwnd.mdf");

 

   
ISingleResult< CustomersByCityResult> result =

    ISingleResult<CustomersByCityResult> result =

       
db.CustomersByCity(
" London" );

        db.CustomersByCity("London");

 

   
foreach (CustomersByCityResult cust
in 结果)

   
{

    {

       
Console.WriteLine(
" CustID = {0};城市= {1}" ,cust.CustomerID,

        Console.WriteLine("CustID={0}; City={1}", cust.CustomerID,

            
cust.City);

            cust.City);

   
}

    }

}

 

如果您想了解更多相关信息,请使用
尝试查看此文档有关"如何:使用存储过程返回行集(LINQ to SQL)&
了解详情

 

我希望这可以帮到你。如果您有任何疑问,请随时告诉我们。

 

祝你有个愉快的一天,

 


这篇关于类似的存储过程会生成不同的返回类型 - 帮助!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆