[英]MVC4 return a stored procedure output with linq to sql
I have a similar issue with thread below ASP.NET MVC4 return output from a stored procedure with Entity Framework 我在ASP.NET MVC4下的线程下有类似的问题, 使用实体框架从存储过程返回输出
I have tried same thing but I am getting the error: 我尝试过同样的事情,但出现错误:
Cannot assign void to an implicitly-typed local variable on
无法将void分配给上的隐式类型的局部变量
Here is my procedure: 这是我的程序:
create PROCEDURE [dbo].[usp_UpdateValuesInTables]
(
@s_clientid int,
@success int output
)
AS
BEGIN
Begin Try
BEGIN TRAN
---- sql statements
COMMIT TRAN
set @success=1
End Try
Begin Catch
ROLLBACK TRAN
set @success=0
End Catch
END
and c# code 和C#代码
int? success = null;
var successCode = Context.usp_UpdateValuesInTables(Convert.ToInt32(obj.SourceClientDropDown),ref success);
Why am I getting that error? 为什么会出现该错误?
If I try to replace var
with int
then I am getting error 如果我尝试用
int
替换var
,那么我会报错
Can not implicitly convert type void to int
无法将类型void隐式转换为int
try this: 尝试这个:
int? success = null;
Context.usp_UpdateValuesInTables(Convert.ToInt32(obj.SourceClientDropDown),ref success);
var successCode = success; //success is the returned result.
Your issue is that the Stored Procedure doesn't actually return a value, but Entity Framework isn't aware of the Void
return. 您的问题是存储过程实际上没有返回值,但是Entity Framework无法
Void
返回。 you need to make sure you use SET NOCOUNT ON
in the stored procedure so that Entity Framework can determine the Void
return and map a default value in. 您需要确保在存储过程中使用
SET NOCOUNT ON
,以便Entity Framework可以确定Void
返回并在其中映射默认值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.