Entity Framework 6 and output parameter


First time working with EF in general and wanted to call a stored procedure. So far I've added the stored procedure in a model (.edmx) and I believe that it's calling properly but I'm not sure how to add the output parameter.

This is what the stored procedure is accepting:

CREATE PROCEDURE [dbo].[uspProperty__Read] 
@Skip           INT = NULL,
@Take           INT = NULL,
@OrderBy        VARCHAR(50) = NULL,
@Return_Code        INT = 0 OUTPUT

I thought I could do this with the output parameter:

  var returnCode = new SqlParameter();
  returnCode.ParameterName = "@ReturnCode";
  returnCode.SqlDbType = SqlDbType.Int;
  returnCode.Direction = ParameterDirection.Output;

  var results = context.uspProperty__Read(10, 10, "NameDesc", out returnCode );

It looks like I've set the stored procedure correctly because "uspProperty_Read" comes up with the intellisense.

Error Message

Any suggestions are greatly appreciated. Thanks!

Accepted Answer

Use ObjectParameter instead of SqlParameter.

Licensed under: CC-BY-SA
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why