title: Deadlock on Linq to Entity Framework Core 2.0 Table
body: <p>I'm getting what I think to be a deadlock when trying to run a bunch of linq queries in parallel.</p>
  
  <p>I am running a <code>Task.WhenAll()</code> on this method:</p>
  
  <pre><code>public async Task&lt;MetabuildScan&gt; GetLatestMetabuildScanAsync(string buildId)
  {
      var metabuildScanStatuses = new[] { "Completed", "Referenced" };
  
      // Get the latest metabuild scan for this image build
      var latestScan = await (from scan in _qsaContext.MetabuildScans
                             where scan.SoftwareImageBuildId == buildId
                             &amp;&amp; metabuildScanStatuses.Contains(scan.SIScanStatus)
                             orderby scan.SIScanStartedOn descending
                             select scan).FirstOrDefaultAsync();
  
      // If there is a related scan, then use that one, else, use the one we just got
      var latestCompletedScanId = latestScan?.RelatedScanId ?? latestScan?.Id;
  
      return await _qsaContext.MetabuildScans
                   .FirstOrDefaultAsync(scan =&gt; scan.Id == latestCompletedScanId);
  }
  </code></pre>
  
  <p>I am getting a <code>System.InvalidOperationException: A second operation started on this context before a previous operation completed. Any instance members are not guaranteed to be thread safe.</code></p>
  
  <p><code>_qsaContext</code> was created using Entity-Framework Core.</p>
  
  <p>At first, I thought the <code>FirstOrDefaultAsync</code> would fix my issue (I had a non-asynchronous <code>FirstOrDefault</code> in there at first), but it didn't.</p>
  
  <p>I'm wondering what the best solution to get around this deadlock would be. The table I am selecting from is a large table, so I can't pull the whole table into memory.</p>