使用Simple.Data时,使用输出参数调用sql server存储过程

时间:2022-08-21 16:40:38

Using Simple.Data, I would like to get the result from an output parameter in a stored procedure. Let's say I have the following SP (disregard the uselessness of it):

使用Simple.Data,我想从存储过程中的输出参数中获取结果。假设我有以下SP(无视它的无用性):

CREATE PROCEDURE [dbo].[TestProc]
    @InParam int,
    @OutParam int OUTPUT
AS
BEGIN
    SELECT @OutParam = @InParam * 10
END

When I call it with Simple.Data, I use the following code.

当我用Simple.Data调用它时,我使用以下代码。

var db = Database.Open();

int outParam;
var result = db.TestProc(42, out outParam);

Console.WriteLine(outParam); // <-- == 0
Console.WriteLine(result.OutputValues["OutParam"]); // <-- == 420

It feels like outParam should contain the value, and not the OutputValues dictionary. So my question is: Is there a nicer way to get the result from OutParam in this particular case?

感觉outParam应该包含值,而不是OutputValues字典。所以我的问题是:在这种特殊情况下,是否有更好的方法可以从OutParam获得结果?

1 个解决方案

#1


3  

Unfortunately, out parameters are not supported by the dynamic binding infrastructure used by Simple.Data, as they are not supported in all CLR languages.

遗憾的是,Simple.Data使用的动态绑定基础结构不支持out参数,因为并非所有CLR语言都支持它们。

I am open to suggestions for better syntax, though.

不过,我愿意接受更好的语法建议。

#1


3  

Unfortunately, out parameters are not supported by the dynamic binding infrastructure used by Simple.Data, as they are not supported in all CLR languages.

遗憾的是,Simple.Data使用的动态绑定基础结构不支持out参数,因为并非所有CLR语言都支持它们。

I am open to suggestions for better syntax, though.

不过,我愿意接受更好的语法建议。