title: EF Core DbContext Where Async
body: <p>I'm trying to execute a query that contains a WHERE as an Async function. Just like using the <a href="https://docs.microsoft.com/en-us/dotnet/api/system.data.entity.queryableextensions.firstasync?view=entity-framework-6.2.0" rel="nofollow noreferrer"><code>FirstAsync</code></a> action, but there's no <code>WhereAsync</code> so I was wondering if there is some workaround. </p>
  
  <p>I have an <code>ApplicationRepository</code> object that has an <code>GetEntitiesAsync</code> function and I tried this:</p>
  
  <pre class="lang-cs prettyprint-override"><code>public async Task&lt;IEnumerable&lt;TEntity&gt;&gt; GetEntitiesAsync&lt;TEntity&gt;(Func&lt;TEntity, bool&gt; selector) where TEntity : class =&gt; 
              await _context.Set&lt;TEntity&gt;().Where(selector).AsQueryable().ToArrayAsync();
  </code></pre>
  
  <p>However, this line of code throws an exception:</p>
  
  <pre><code>System.InvalidOperationException: The source IQueryable doesn't implement IAsyncEnumerable&lt;OneStopApp.Models.CustomForm&gt;. Only sources that implement IAsyncEnumerable can be used for Entity Framework asynchronous operations.
  </code></pre>