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

Tim
  • 1,249
  • 5
  • 28
  • 54
  • this discussion might be useful https://stackoverflow.com/questions/22068027/executing-sql-stored-procedure-with-output-parameter-from-entity-framework – twinmind Jun 14 '18 at 23:54
  • @twinmind, thanks. I already worked through that post prior to posting this. – Tim Jun 15 '18 at 00:11

1 Answers1

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

Tim
  • 1,249
  • 5
  • 28
  • 54