0

So, I'm trying to execute a SP from Entity Framework 6 and return the output parameter @AffectedRowCount that holds the number of rows that were affected by the execution. Below is my code and a screenshot of the SSMS execution showing the correct result. rowCount.Value is null everytime it executes through C# even after I reset the data. Any thoughts.

    public int UpdateStagingTable()
    {
        var rowCount = new ObjectParameter("AffectedRowCount", typeof(Int32));
        be.sp_LoanCategoryMonitor(rowCount);
        return Convert.ToInt32(rowCount.Value);
    }

This is the autogened Code from the dbContext

public virtual ObjectResult<sp_LoanCategoryMonitor_Result> sp_LoanCategoryMonitor(ObjectParameter affectedRowCount)
    {
        return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<sp_LoanCategoryMonitor_Result>("sp_LoanCategoryMonitor", affectedRowCount);
    }

SSMS Execution

DECLARE @return_value int,
        @AffectedRowCount int

EXEC    @return_value = [dbo].[sp_LoanCategoryMonitor]
        @AffectedRowCount = @AffectedRowCount OUTPUT

SELECT  @AffectedRowCount as N'@AffectedRowCount'

SELECT  'Return Value' = @return_value

SSMS Results

enter image description here

enter image description here

2
  • this discussion might be useful stackoverflow.com/questions/22068027/… Commented Jun 14, 2018 at 23:54
  • @twinmind, thanks. I already worked through that post prior to posting this. Commented Jun 15, 2018 at 0:11

1 Answer 1

0

I found the issue. The developer who created the SP for whatever reason added a select statement in the last statement in the SP. This was interfering with the output parameter. I updated the SP then cleaned my .edmx file of the SP and then added it back. I ran it and it ran as expected.

enter image description here

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

Comments

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.