title: Many nested AggregateExceptions
body: <p>Working with Entity Framework 7, I made a simple mistake with some linq (used Skip and forgot to include my OrderBy clause).</p>
  
  <p>The exception that was thrown by this included a number of nested aggregate exceptions.</p>
  
  <p>The code that generates (and catches) the exception is:</p>
  
  <pre><code>int[] newIds;
  try
  {
      newIds = await db.Products
          .Where(p =&gt; p.PortalId == portalId)
          .Skip(ids.ProductIds.Count) //Skip the rows already read
          .Take(takeTotal) //get the next block
          .Select(p =&gt; p.ProductId)
          .ToArrayAsync();
  }
  catch (AggregateException ex)
  {
      Console.WriteLine(ex.Message);
      newIds = new int[] { };
  }
  </code></pre>
  
  <p>The code above is in a repo class called from a Asp.Net 5 WebApi controller. All levels of the call are using async-await.</p>
  
  <p>However the aggregate exception that I got from this was (this is dumped to the immediate window from the catch block shown above):</p>
  
  <blockquote>
    <p>System.AggregateException: One or more errors occurred. --->
    System.AggregateException: One or more errors occurred. --->
    System.AggregateException: One or more errors occurred. --->
    System.AggregateException: One or more errors occurred. --->
    System.AggregateException: One or more errors occurred. --->
    System.AggregateException: One or more errors occurred. --->
    System.InvalidOperationException: A query containing the Skip operator
    must include at least one OrderBy operation.   at
    Microsoft.Data.Entity.Relational.Query.Sql.DefaultSqlQueryGenerator.GenerateLimitOffset(SelectExpression
    selectExpression)   at
    Microsoft.Data.Entity.Relational.Query.Sql.DefaultSqlQueryGenerator.VisitSelectExpression(SelectExpression
    selectExpression)   at
    Microsoft.Data.Entity.Relational.Query.Expressions.SelectExpression.Accept(ExpressionTreeVisitor
    visitor)   at
    Microsoft.Data.Entity.Relational.Query.Sql.DefaultSqlQueryGenerator.GenerateSql(SelectExpression
    selectExpression, IDictionary`2 parameterValues)
    etc etc</p>
  </blockquote>
  
  <p>Here the actual exception has ended up wrapped by a whole bunch of layers of aggregate exception (6 nested layers). I understand why I'm getting an aggregate exception, but wondered why so many of them? More so since I'm looking at the exception before it has bubbled back up to the controller entry-point.</p>
  
  <p>Would this be a result of a number of layers of async-await, (don't think I have as many as 6) or could it be an issue in the EF7 implementation?</p>
  
  <p>This is currently using EF 7 release 7.0.0-beta4.</p>