title: ExecuteSqlRawAsync returns -1 in Entity Framework 3.1
body: <p>In my <strong>ASP.NET Core 3.1</strong>  web application, I am mostly using stored procedures. When using <code>ExecuteSqlRawAsync</code> in <strong>Entity Framework Core</strong> it always returns <code>-1</code>. Below given is my generalized method to execute stored procedures.</p>
  
  <pre><code>  public async Task&lt;int&gt; ExecuteSqlNonQuery(string StoredProcName, params object[] parameters)
    {
          int iTotalRecordsAffected = 0;
  
          List&lt;TEntity&gt; listOfObject = null;
  
          try
          {
              if (!string.IsNullOrEmpty(StoredProcName))
              {
                  StringBuilder sbStoredProc = new StringBuilder();
                  sbStoredProc.Append("Exec ");
                  sbStoredProc.Append(StoredProcName);
  
                  if (parameters != null)
                  {
                      foreach (SqlParameter item in parameters)
                      {
                          if (listOfObject == null)
                          {
                              sbStoredProc.Append(" @");
                              listOfObject = new List&lt;TEntity&gt;();
                          }
                          else
                          {
                              sbStoredProc.Append(", @");
                          }
                          sbStoredProc.Append(item.ParameterName.Replace("@", ""));
                          if (item.Direction == System.Data.ParameterDirection.Output)
                          {
                              sbStoredProc.Append(" OUT");
                          }
                      }
                  }
  
                  iTotalRecordsAffected = await _DBContext.Database.ExecuteSqlRawAsync(sbStoredProc.ToString(), parameters);
              }
          }
          catch (Exception ex)
          {
  
          }
          finally
          {
              if (_DBContext.Database.GetDbConnection().State == System.Data.ConnectionState.Open)
              {
                  _DBContext.Database.GetDbConnection().Close();
              }
          }
  
          return iTotalRecordsAffected;
   }
  </code></pre>
  
  <p>Here is my controller method that calls a SP to update data.</p>
  
  <pre><code>   public async Task&lt;int&gt; UpdateCustomerData(EditCustomerDetail editCustomerDetail)
      {
          int iTotalRecordsEffected = 0;
  
          try
          {
              List&lt;SqlParameter&gt; sqlParamList = new List&lt;SqlParameter&gt;()
              {
                  new SqlParameter("@CustomerID",editCustomerDetail.CorporateID),
                  new SqlParameter("@CustomerName",editCustomerDetail.CorporateName),
                  new SqlParameter("@CustomerAddress",editCustomerDetail.Address),
                  new SqlParameter("@City",editCustomerDetail.City),
                  new SqlParameter("@CountryID",editCustomerDetail.CountryID),
                  new SqlParameter("@StateID",editCustomerDetail.StateID),
                  new SqlParameter("@Description",editCustomerDetail.Description),
                  new SqlParameter("@Phone",editCustomerDetail.Phone),
                  new SqlParameter("@Fax",editCustomerDetail.Fax),
                  new SqlParameter("@ModifiedBy",editCustomerDetail.UserID)
              };
  
              iTotalRecordsEffected = await _unitOfWork.GetRepository&lt;EditCustomerDetail&gt;().ExecuteSqlNonQuery("UpdateCustomerDetails", sqlParamList.ToArray());
          }
          catch (Exception ex)
          {
  
          }
          finally
          {
  
          }
          return iTotalRecordsEffected;
      }
  </code></pre>
  
  <p>Any suggestion what I am doing wrong?</p>