title: In Entity Framework when should I use FirstOrDefaultAsync or FirstOrDefault?
body: <p>I am using Entity Framework in my ASP.NET Web API. In a query method, I could either choose to use the standard LINQ method <code>FirstOrDefault()</code> or the EF method <code>FirstOrDefaultAsync()</code>. When is it correct to use one or other of these?</p>
  
  <p>To my knowledge using:</p>
  
  <pre><code>var users = context.Users.FirstOrDefault(user =&gt; user.id == Id);
  </code></pre>
  
  <p>and</p>
  
  <pre><code>var users = await context.Users.FirstOrDefaultAsync(user =&gt; user.id == Id);
  </code></pre>
  
  <p>will both pause the thread they are running on until the call is returned? The only advantage of the <code>Async</code> method is that it can be <code>Awaited</code> in an <code>Async</code> method. However if that method is also being await then it's irrelevant? Except that you trigger another thread to be created surely?</p>
  
  <pre><code>public async Task MethodOneAsync() {
    await MethodTwoAsync();
  }
  
  public async Task MethodTwoAsync() {
    await context.Users.FirstOrDefaultAsync(..);
    ...
  }
  </code></pre>
  
  <p>Is this the same as doing:</p>
  
  <pre><code>public async void MethodOneAsync() {
    MethodTwo();
    ... await something else to 'please' the async nature, or remove async all together ...
  }
  
  public void MethodTwo() {
    context.Users.FirstOrDefault(..);
    ...
  }
  </code></pre>
  
  <p>Thanks, just trying to clear up my own confusion.</p>
  
  <p>Note: This is the example I mean</p>
  
  <p><a href="https://i.stack.imgur.com/5nsxtm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5nsxtm.png" alt="Async method chain"></a></p>
  
  <p><a href="https://i.stack.imgur.com/aywgfm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aywgfm.png" alt="Sync method chain"></a></p>
  
  <p><a href="https://i.stack.imgur.com/29kSvm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/29kSvm.png" alt="timings and orders"></a></p>
  
  <p>These show what I mean by a chain and the timings (9 and 0) are in milliseconds. So the Async methods took longer to run (relatively).</p>
  
  <p>EDIT:
  In the comments it has been stated that the reason to do this is it releases the thread, however if the method being called is internal to the server then surely it's releasing one thread just to start the called code another thread?</p>