1

I am calling a stored procedure and declare an output paramters:

CREATE PROCEDURE dbo.usp_getIsReadyForProcess
@VideoId INT ,
@val INT OUTPUT
AS
BEGIN
BEGIN TRY
    BEGIN TRANSACTION
-- LOCK ROW UNTIL END OF TRANSACTION
        SELECT * FROM dbo.ProcessStatus WITH (ROWLOCK, HOLDLOCK) WHERE VideoId = @VideoId

And then setting the value throughout the transaction

  --If there is no row count
IF @@ROWCOUNT = 0
BEGIN
    SET @val = 0
END

-- If video is already in process
ELSE IF @statusCode > 1
BEGIN
    SET @val = 0
END

...... more if blocks

          -- RELEASE LOCK
    COMMIT TRANSACTION
END TRY   

Here is the c# code for getting the output parameter:

        using (var db = EntityFactory.GetInstance())
        {
            ObjectParameter objParam = new ObjectParameter("val", typeof(int));
            db.usp_getIsReadyForProcess(videoId, objParam);

            return (int)objParam.Value == 1;
        }

... But then objParam.Value is null no matter what I do.

So I dig a little deeper and uncover an exception that was handled already,

Message: Method may only be called on a Type for which Type.IsGenericParameter is true.

What am i doing wrong? I tried type(bool, int32, string) .. nothing works

abatishchev
  • 98,240
  • 88
  • 296
  • 433
Sherman Szeto
  • 2,325
  • 4
  • 18
  • 26
  • I'm not sure EF supports output parameters. – DavidG Feb 22 '15 at 22:56
  • 1
    Have you looked at this post: http://stackoverflow.com/questions/5881359/i-cannot-get-the-output-parameter-when-use-function-import-by-entity-framework – David Tansey Feb 22 '15 at 23:00
  • @DavidTansey Hmm, good link. So you need to ensure the procedure has executed before checking the return value. – DavidG Feb 22 '15 at 23:03

1 Answers1

1

Your stored procedure returns a resultset, due to this line:

SELECT * FROM dbo.ProcessStatus WITH (ROWLOCK, HOLDLOCK) WHERE VideoId = @VideoId

You can either change the SQL to something like:

DECLARE @RowCount INT
SELECT @RowCount = COUNT(*) FROM dbo.ProcessStatus WITH (ROWLOCK, HOLDLOCK) WHERE VideoId = @VideoId

Or you can capture the resultset in your code:

var resultSet = db.usp_getIsReadyForProcess(videoId, objParam);
EkoostikMartin
  • 6,831
  • 2
  • 33
  • 62