title: How to get Multiple OUTPUT parameters from stored procedure EF Core 3.1
body: <p>I have been trying to modify the accepted answer <a href="https://stackoverflow.com/questions/43621262/get-output-parameter-value-of-a-stored-procedure-using-ef-core">here</a> which seems to leverage <a href="https://docs.microsoft.com/en-us/dotnet/api/microsoft.entityframeworkcore.storage.relationaldatareader.read?view=efcore-3.1#Microsoft_EntityFrameworkCore_Storage_RelationalDataReader_Read" rel="nofollow noreferrer">RelationalDataReader</a>  in order to get back 2 OUTPUT parameters for some calculated dates from an API that the Product Owners wished to be as much database driven as possible.</p>
  <p>I have a stored procedure that calculates begin and end dates from the SQL queries I have stored in a table so that all they have to to to add another date range is to add it to the table and the rest will fall into place on the UI and the rest of the pipeline.</p>
  <p>The first part is the same for the RDFacadeExtensions class but I thought that I could simply add more parameters and get them back, but I seem to be missing something.</p>
  <pre><code>var ID = new SqlParameter(&quot;ID&quot;, 5)
  {
      Direction = ParameterDirection.Input,
      DbType = DbType.Int32,
      Size = 500
  };
  
  var _beginDate = new SqlParameter(&quot;BeginDate&quot;, &quot;&quot;)
  {
      Direction = ParameterDirection.Output,
      DbType = DbType.String,
      Size = 500
  };
  
  var _endDate = new SqlParameter(&quot;EndDate&quot;, &quot;&quot;)
  {
      Direction = ParameterDirection.Output,
      DbType = DbType.String,
      Size = 500
  };
  </code></pre>
  <p>This all seems normal and then I do the following:</p>
  <pre><code>string begin;
  string end;
  var sql = $&quot;exec [dbo].[GetDateRange] @ID, @BeginDate OUTPUT, @EndDate OUTPUT&quot;;
  
  using (var dr = context.Database.ExecuteSqlQuery(sql, ID, _beginDate, _endDate))
  {
      while (dr.DbDataReader.Read())
      {
          var thing = dr.DbDataReader[0].ToString();
      }
      dr.DbDataReader.Close();
      begin = _beginDate.Value.ToString();
      end = _endDate.Value.ToString();
  }
  </code></pre>
  <p>Before the end of the using I briefly get the first date but I never seem to be able to get the second date. I also have empty strings once the datareader is closed.</p>
  <p>If it matters, my stored procedure is simply this:</p>
  <pre><code>    @ID INT,
      @BeginDate DATE OUTPUT,
      @EndDate DATE OUTPUT
  BEGIN
      SET NOCOUNT ON;
      DECLARE @Query1 NVARCHAR(1000)
      DECLARE @Query2 NVARCHAR(1000)
  
      SELECT @Query1 = BeginDate,
             @Query2 = EndDate 
      FROM DateRange 
      WHERE ID = @ID
      
      DECLARE @ParmDefinition1 NVARCHAR(50) = N'@BeginDateOUT DATE OUTPUT';
      DECLARE @ParmDefinition2 NVARCHAR(50) = N'@EndDateOUT DATE OUTPUT';
  
      EXEC sp_executesql @Query1, @ParmDefinition1, @BeginDateOUT = @BeginDate OUTPUT
      EXEC sp_executesql @Query2, @ParmDefinition2, @EndDateOUT = @EndDate OUTPUT
  END
  </code></pre>
  <p>Or perhaps my stored procedure is the issue. I get one date but can only hold it for a short time. The issue with sp_executesql is that it has to go to an OUTPUT parameter and I can't assign the result to anything but an INT variable. I need two dates from the stored code in the table.</p>
  <p>If there is a way to do that and only return what essentially amounts to a small table result that would be ideal.</p>
  <p>Thanks you any that can point me in the right direction.</p>