Working with Entity Framework 7, I made a simple mistake with some linq (used Skip and forgot to include my OrderBy clause).
The exception that was thrown by this included a number of nested aggregate exceptions.
The code that generates (and catches) the exception is:
int[] newIds;
try
{
newIds = await db.Products
.Where(p => p.PortalId == portalId)
.Skip(ids.ProductIds.Count) //Skip the rows already read
.Take(takeTotal) //get the next block
.Select(p => p.ProductId)
.ToArrayAsync();
}
catch (AggregateException ex)
{
Console.WriteLine(ex.Message);
newIds = new int[] { };
}
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.
However the aggregate exception that I got from this was (this is dumped to the immediate window from the catch block shown above):
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
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.
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?
This is currently using EF 7 release 7.0.0-beta4.