I have a simple c# application that uses the Entity Framework 5.0 and should call a stored procedure with output parameters. The problem is that it doesn't work, and instead, it returns -1.
The c# code that I have looks like that:
// Define the output paramaters
SqlParameter operatorID = new SqlParameter("@operatorID", SqlDbType.Int);
operatorID.Direction = ParameterDirection.Output;
SqlParameter operatorCode = new SqlParameter("@operatorCode", SqlDbType.Int);
operatorCode.Direction = ParameterDirection.Output;
var parameters = new List<object>();
parameters.Add(operatorID);
parameters.Add(operatorCode);
var noOutput = context.Database.ExecuteSqlCommand("EXEC my_sp_name @operatorID, @operatorCode", parameters.ToArray());
The stored procedure looks like that:
CREATE PROCEDURE [dbo].[my_sp_name]
(
@operatorID int OUTPUT
,@operatorCode int OUTPUT
)
AS
SET @operatorID = 123
I know it doesn't make sense, but it's just for a test.
The problem after executing the c# code is that the noOutput value is -1 and the operatorID value is empty, where I expect it to be 123.
Does anybody have an idea what I do wrong?