title: Ef core: Sequence contains no element when doing MaxAsync
body: <p>I'm using ef core in my asp core API project.
  I have to find the highest order index.</p>
  
  <p>Example:</p>
  
  <p>Data table: <code>Id, ForeignId, OrderIndex</code></p>
  
  <p>So I'm doing:</p>
  
  <pre><code>var highestOrderIndex = await _context
                  .ExampleDbSet
                  .Where(x =&gt;
                      x.ForeignId == foreignId)
                  .MaxAsync(x =&gt;
                      x.OrderIndex);
  </code></pre>
  
  <p>The problem is when the example db set is containing 0 elements. This will throw an exception: <code>Sequence contains no element</code>.</p>
  
  <p>Is there an elegant way to do this? Because I don't want to get all the elements from the database. And it should be async.</p>
  
  <p>Thanks</p>