获取甲骨文OUT参数的值从存储过程调用使用Dapper.NET [英] Get value of Oracle OUT parameter from a stored procedure call using Dapper.NET
问题描述
编辑:使用执行
方法,而不是查询
/ QueryMultiple
的方法,我的 OUT_SUCCESS
参数现在有一个 AttachedParam
与一个的OracleParameter
有返回值。因此这将工作,如果,例如,我的仅的检索非游标参数需要的。然后,我可以使用执行
与所有非游标输出参数的程序和查询
/ QueryMultiple
与仅的指针输出参数的过程。但是,如果我需要调用存储过程具有双方光标和非游标输出参数,这是常有的情况?
Using the Execute
method instead of the Query
/QueryMultiple
methods, my OUT_SUCCESS
parameter now has an AttachedParam
with with an OracleParameter
that has the returned value. So this would work if, for instance, I only needed to retrieve non-cursors parameters. Then I could use Execute
for procedures with all non-cursor output parameters and Query
/QueryMultiple
for procedures with only cursor output parameters. But what if I need to call a stored procedure that has both cursor and non-cursor output parameters, as is often the case?
使用 Dapper.NET
和 OracleDynamicParameters
类我已经顺利返回并映射多个 IN OUT
REF CURSOR
S,但我不能获得价值单一 OUT
参数。
Using Dapper.NET
and the OracleDynamicParameters
class I have successfully returned and mapped multiple IN OUT
REF CURSOR
s, but I cannot get the value a single OUT
parameter.
例如,我试图调用存储过程具有以下规范:
For instance, I am trying to call a stored procedure with the following spec:
PROCEDURE DO_SOMETHING (
OUT_SUCCESS OUT VARCHAR2
)
为此我创建了一个相应的C#类来模拟它,它包含的方法来获得 OracleDynamicParameters
的的CommandText
,系统等等,并且还包括自动实现的属性的对于每个参数的
for which I have created a corresponding C# class to model it, which contains methods to get the OracleDynamicParameters
, the CommandText
, and so forth, and also includes an auto-implemented property for each parameter
public class DO_SOMETHING {
... //code to return parameters, etc
public string OUT_SUCCESS { get; set; }
...
}
和我已经尝试了所有的语法如下的:
and I have tried all of the following syntax:
using (var gridReader = Connection.QueryMultiple(nModel.CommandText(), param: nModel.DynamicParameters(), commandType: nModel.CommandType()))
{
OUT_SUCCESS = ((OracleDynamicParameters)Model.DynamicParameters()).Get<string>("OUT_SUCCESS"); // 1
OUT_SUCCESS = gridReader.Read<string>().Single(); //2
OUT_SUCCESS = gridReader.Read<DO_SOMETHING>().Single().OUT_SUCCESS; //3
}
但他们没有工作:
but none of them work:
- 的
AttachedParam
是空
与名称的参数OUT_SUCCESS
(虽然我能看到的参数存在) - 的
gridReader
报道说,序列不包含任何元素,可能是因为它不知道如何读一个串出的响应。 - 在这其中似乎是最有前途的 -
InvalidArgumentException
:在gridReader
建议我说:当使用多映射的API确保您设置splitOn参数,如果你有钥匙比ID等,但我真的不知道这是怎么有关我的问题。
- The
AttachedParam
isnull
for the parameter with name"OUT_SUCCESS"
(although I can see the parameter exists) - The
gridReader
reports that the "sequence contains no elements", probably because it has no idea how to read a string out of the response. - This one seems the most promising -
InvalidArgumentException
: thegridReader
advises me that "When using the multi-mapping APIs ensure you set the splitOn param if you have keys other than Id", but I'm not really sure how this is pertinent to my problem.
顺便说一句,我不知道该程序已成功执行,因为ODP.NET不会产生异常,我看到的结果行保留在数据库中。
By the way, I do know that the procedure is successfully executing because ODP.NET does not produce an exception and I see the resulting rows persisted in the database.
我不知道如何着手,但我真的很喜欢用小巧精致的,因为这是最后剩下的障碍攀升。任何帮助总是AP preciated。
I don't know how to proceed, but I'd really like to use Dapper, as this is the last remaining hurdle to climb. Any help is always appreciated.
推荐答案
关闭连接,然后读取输出参数。
Close the connection, then read the output parameter.
这篇关于获取甲骨文OUT参数的值从存储过程调用使用Dapper.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!