title: Call stored procedure that returns scalar value in Entity Framework Core
body: <p>Using .Net Core and Entity Framework Core 5.0.7 I want to call a stored procedure that returns a scalar value.</p>
  <p>As far as I understood to call a stored procedure it must returns an entity model.</p>
  <p>Let's say I have a product table in SQL and stored procedure returns a set of products so we call it like</p>
  <pre><code> var products = (await _dbContext.priducts.FromSqlRaw($&quot;sp_GetProducts&quot;).ToListAsync())
  </code></pre>
  <p>But now I have another case which is returning only a scalar value.I read many articles and questions here in Stackoverflow so I came up with one working solution which is not good in my opinion.</p>
  <p>I have created an entity model called <code>ScalarBool</code></p>
  <pre><code>public partial class ScalarBool
  {
      public bool Value { get; set; }
  
      public override string ToString()
      {
          return Value.ToString();
      }
  }
  </code></pre>
  <p>and added it to my <code>dbcontext</code></p>
  <pre><code>modelBuilder.Entity&lt;ScalarBool&gt;().HasNoKey();
  </code></pre>
  <p>We are using database-first approach. So other developers may do dbScaffold with force and that model will disappear because it's not actually a table in SQL Server.</p>
  <p>Other solution I got which is not working is below</p>
  <pre><code>        SqlParameter orderId = new SqlParameter(&quot;@orderid&quot;,orderId);
          SqlParameter customerid = new SqlParameter(&quot;@customerid&quot;, customerId);
          SqlParameter isDelivered = new SqlParameter
          {
              ParameterName = &quot;@Value&quot;,
              SqlDbType = System.Data.SqlDbType.BigInt,
              Direction = System.Data.ParameterDirection.Output
          };
  
          await _dbContext.Database.ExecuteSqlCommandAsync(&quot;[dbo].[is_delivered] @orderid , @customerid, @Value&quot;, orderId , customerid, isDelivered);
          var isDelivered = Convert.ToInt64(isDelivered.Value);
  </code></pre>
  <p>But I got this error</p>
  <blockquote>
  <p>'DatabaseFacade' does not contain a definition for 'ExecuteSqlCommandAsync' and no accessible extension method 'ExecuteSqlCommandAsync' accepting a first argument of type 'DatabaseFacade' could be found (are you missing a using directive or an assembly reference?)</p>
  </blockquote>
  <p>So what is the best solution here?</p>