title: Entity Framework Core DbContext.Database.ExecuteSqlRawAsync() returns -1 as "rowsAffected" return value. What does this mean?
body: <p>When I call a stored procedure in MSQL Server using Entity Framework Core, I get a return value of -1. This is the number of affected rows.</p>
  <p>First of all, this is wrong as my stored procedure deletes multiple entries from a table. What is even more strange to me is that the value is negative. Usually I'd assume this indicates an error, but my stored procedure is executed and the data is changed as expected.</p>
  <p>Here's my C# code:</p>
  <pre class="lang-cs prettyprint-override"><code>var rowsAffected = await this.dbContext.Database.ExecuteSqlRawAsync(&quot;dbo.sp_DeleteSomeStuff&quot;).ConfigureAwait(false);
  </code></pre>
  <p>The stored procedure looks like this:</p>
  <pre class="lang-sql prettyprint-override"><code>CREATE PROCEDURE sp_DeleteSomeStuff
  AS
  BEGIN
      BEGIN TRANSACTION;
          DECLARE @result int;
          EXEC @result = sp_getapplock @Resource = 'DeleteSomeStuffLock',
                                       @LockOwner='Transaction',
                                       @LockMode = 'Exclusive';
  
          -- result code 0 or 1 = success (error codes are negative)
          IF @result &gt;= 0
          BEGIN
              SET NOCOUNT ON;
  
              DELETE FROM [dbo].[MyTable] 
              WHERE [Expiration] &lt; (CURRENT_TIMESTAMP);
  
              COMMIT TRANSACTION;
          END
          ELSE
          BEGIN
              ROLLBACK TRANSACTION;
          END;
  
          RETURN @result;
  END
  GO
  </code></pre>
  <p>What does the -1 mean? And is there a way to get the actual count of affected rows from my stored procedure?</p>