title: Entity Framework - async select with where condition
body: <p>I'm using ASP.NET Core with Entity Framework.</p>
  
  <p>First I select an employee, and then all employees that satisfy a condition (for the purpose of displaying what works):</p>
  
  <pre><code>var a = db.Employee.FirstOrDefault();
  var b = db.Employee.Where(x =&gt; x.FirstName == "Jack");
  </code></pre>
  
  <p>Now I try the same, but asynchronously:</p>
  
  <pre><code>var c = await db.Employee.FirstOrDefaultAsync();
  var d = await db.Employee.Where(x =&gt; x.FirstName == "Jack");
  </code></pre>
  
  <p>However, for the "WHERE" there's no async version, and the second line of code doesn't compile - I get an error</p>
  
  <blockquote>
    <p>... does not contain a definition for GetAwaiter ...</p>
  </blockquote>
  
  <p>How do I perform a <code>SELECT</code> with a <code>WHERE</code> condition in this case?</p>
  
  <hr>
  
  <p>OK, from the answers I see that ToListAsync() will resolve the "var d = ..." line. However, there's a continuation to this issue, I wasn't aware before that it matters. In this case I'm just trying to select a set of records that will be deleted, I'm not interested in accessing the data for the purpose of manipulating it further in the code. So I amended all 4 code versions with purpose to delete one or more records, synchronously or asynchronously. Why does only the last one need a ToListAsync(), won't that actually retrieve the records from the database?</p>
  
  <pre><code>var a = db.Employee.FirstOrDefault();
  db.Employee.Remove(a);
  // db.Employee.RemoveRange(a); &lt;- this also works?
  db.SaveChanges();
  
  var b = db.Employee.Where(x =&gt; x.FirstName == "Jack");
  db.Employee.RemoveRange(b);
  db.SaveChanges();
  
  var c = await db.Employee.FirstOrDefaultAsync();
  db.Employee.Remove(c);
  await db.SaveChangesAsync();
  
  var d = await db.Employee.Where(x =&gt; x.FirstName == "Jack").ToListAsync();
  db.Employee.RemoveRange(d);
  await db.SaveChangesAsync();
  </code></pre>