title: Access result from SELECT statement in stored procedure using EF Core and ExecuteSqlCommandAsync
body: <p>I'm trying to use <code>ExecuteSqlCommandAsync</code> from EF Core to get the result of a select query in a somewhat odd legacy stored procedure that has an empty <code>RETURN</code> statement.</p>
  
  <p>The stored procedure looks like this:</p>
  
  <pre><code>CREATE PROCEDURE [dbo].[SelectNextCounter]
  (
  @CounterName nvarchar(50)
  )
  AS
      UPDATE  counter
      SET NextValue = NextValue + 1
      WHERE   CounterName = @CounterName
      SELECT  NextValue
      FROM    counter
      WHERE   counterName = @CounterName
  RETURN
  GO
  </code></pre>
  
  <p>Using this code I'm able to access the <code>RETURN</code> value of the stored procedure (though what I'm really interested in is <code>NextValue</code>): </p>
  
  <pre><code>var counterName = new SqlParameter
  {
      ParameterName = "@CounterName",
      Value = "CustomerNumber",
      SqlDbType = SqlDbType.NVarChar
  };
  var returnValue = new SqlParameter
  {
      ParameterName = "@return_value",
      Direction = ParameterDirection.Output,
      SqlDbType = SqlDbType.Int
  };
  
  await _context
      .Database
      .ExecuteSqlCommandAsync(
          "EXEC @return_value = SelectNextCounter @CounterName", counterName, returnValue
      );
  </code></pre>
  
  <p>I can then get the value through <code>returnValue.Value</code> (which is always 0, because of the empty <code>RETURN</code> statement). However, is there any way to get the value from <code>NextValue</code> using EF Core? Seems like <code>FromSql</code> might work but I'm really just interested in getting a single value back, not an entity. <a href="https://stackoverflow.com/questions/18901545/return-result-from-select-query-in-stored-procedure-to-a-list">This answer</a> seems to do what I want but I would rather use EF Core than <code>SqlCommand</code>, if possible.</p>