title: Call stored procedure from EF asynchronously using C# inside async method
body: <p>We are moving to Entity Framework, however we have a large number of stored procedures. If our Web API uses an async/await pattern all the way to the stored procedure call, how do I handle the call? Can I/should I make it async as well?</p>
  
  <p>I have a db context and I can call my stored procedure <code>Foo</code> synchronously. This works however the calling code is all wrapped with async/await keywords. The stored procedure in question is also a <code>Select</code> and not an <code>Insert/Update/Delete</code>. I cannot use <code>ToListAsync()</code> on the <code>context.Foo</code> call, if I try </p>
  
  <pre><code>context.Database.ExecutSQLCommandAsync() 
  </code></pre>
  
  <p>I only get a <code>Task&lt;int&gt;</code> back and not my object. Is there a best practice here?</p>
  
  <pre><code>public async Task&lt;List&lt;FooData&gt;&gt; GetFoo(string param)
  {
      List&lt;FooData&gt; dataList = new List&lt;FooData&gt;();
  
      using(dbEntities context = new dbEntities(connectionstring))
      {
          //  this runs as expected
          var result =  context.Foo(param).ToList();
  
          if(result != null)
          {
              result.ForEach(delegate(Foo_Result item)
                                 {
                                     //  load object
                                 });
          }
      }
  
      return dataList;
  }
  </code></pre>
  
  <p>I suppose I could do this </p>
  
  <pre><code>var result = await Task.Run(()=&gt; context.Foo(param).ToList());
  </code></pre>
  
  <p>but this is an Entity Framework db call and not an CPU intensive process. Is there a best practice to follow here? Thanks</p>