[英]EF6 Stored Procedure does not accept parameters
I am using EF6 and I need to execute stored procedure.我正在使用 EF6,我需要执行存储过程。 It takes two parameters:
它需要两个参数:
mIIN varchar(12)
, which is input string mIIN varchar(12)
,即输入字符串mXMLOutput varchar(max)
, which is the result of execution mXMLOutput varchar(max)
,这是执行的结果It works fine when I call it from Management Studio.当我从 Management Studio 调用它时,它工作正常。
However, when I use the following code:但是,当我使用以下代码时:
var iinParameter = new SqlParameter("@mIIN", SqlDbType.VarChar, 12) { Value = "123456123456" };
var outputParameter = new SqlParameter("@mXMLContent", SqlDbType.VarChar, -1) { Direction = ParameterDirection.Output };
_dbContext.Database.ExecuteSqlCommand("GetInfo", iinParameter, outputParameter);
which results in the error导致错误
Procedure or function 'GetInfo' expects parameter '@mIIN', which was not supplied
过程或 function 'GetInfo' 需要参数 '@mIIN',但未提供
EF6 contains the following messages: EF6 包含以下消息:
Started transaction at 15.12.2015 14:27:27 +06:00
GetInfo
-- @mIIN: '123456123456' (Type = AnsiString, IsNullable = false, Size = 12)
-- @mXMLContent: '' (Type = AnsiString, Direction = Output, IsNullable = false, Size = -1)
-- Executing at 15.12.2015 14:27:27 +06:00
-- Failed in 2 ms with error: Procedure or function 'GetInfo' expects parameter '@mIIN', which was not supplied.
What can cause that problem?什么会导致这个问题? I am passing this parameter, why doesn't it accept it?
我正在传递这个参数,为什么它不接受它?
这应该工作:
_dbContext.Database.ExecuteSqlCommand("exec GetInfo @mIIN, @mXMLContent OUTPUT", iinParameter, outputParameter);
I think that problem is in your subprocedure. 我认为问题出在您的子过程中。 Log message tells that parameter was suplied to
GetInfo
, and error is related to subprocedure IBRC_GetClientInfo
. 日志消息表明该参数已提供给
GetInfo
,并且错误与子过程IBRC_GetClientInfo
。 Check your procedure that parameter inside is properly passed. 检查您的过程,以确保正确传递了内部参数。
There are few things that are must to call a store procedure using EF6.使用 EF6 调用存储过程需要做的事情很少。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.