0

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!

1

1 Answer 1

2

Use ObjectParameter instead of SqlParameter.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the help! That resolved the issue. I can't believe I didn't look for ObjectParameter when it was staring in my face. Thanks again!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.