Skip to content

Commit

Permalink
Further updates to query exception throwing
Browse files Browse the repository at this point in the history
Fixes #16133
  • Loading branch information
ajcvickers committed Aug 20, 2019
1 parent 5590a29 commit 9fc67e2
Show file tree
Hide file tree
Showing 14 changed files with 161 additions and 150 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ protected override Expression VisitExtension(Expression extensionExpression)
return _clientEval ? base.VisitExtension(includeExpression) : null;

default:
throw new InvalidOperationException(CoreStrings.TranslationFailed(extensionExpression.Print()));
throw new InvalidOperationException(CoreStrings.QueryFailed(extensionExpression.Print(), GetType().Name));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,7 @@ protected override ShapedQueryExpression TranslateGroupBy(ShapedQueryExpression
/// </summary>
protected override ShapedQueryExpression TranslateGroupJoin(ShapedQueryExpression outer, ShapedQueryExpression inner, LambdaExpression outerKeySelector, LambdaExpression innerKeySelector, LambdaExpression resultSelector)
{
throw new InvalidOperationException(CoreStrings.TranslationFailed(
outerKeySelector.Print() + "; " + innerKeySelector.Print() + "; " + resultSelector.Print()));
return null;
}

/// <summary>
Expand Down
8 changes: 5 additions & 3 deletions src/EFCore.Relational/Query/SqlExpressionFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ private SqlExpression ApplyTypeMappingOnSqlUnary(
break;

default:
throw new InvalidOperationException(CoreStrings.TranslationFailed(sqlUnaryExpression.Print()));
throw new InvalidOperationException(
$"The unary expression operator type {sqlUnaryExpression.OperatorType} is not supported.");
}

return new SqlUnaryExpression(
Expand Down Expand Up @@ -397,11 +398,12 @@ public virtual InExpression In(SqlExpression item, SqlExpression values, bool ne

public virtual InExpression In(SqlExpression item, SelectExpression subquery, bool negated)
{
var typeMapping = subquery.Projection.Single().Expression.TypeMapping;
var sqlExpression = subquery.Projection.Single().Expression;
var typeMapping = sqlExpression.TypeMapping;

if (typeMapping == null)
{
throw new InvalidOperationException(CoreStrings.TranslationFailed(item.Print()));
throw new InvalidOperationException($"The subquery '{subquery.Print()}' references type '{sqlExpression.Type}' for which no type mapping could be found.");
}

item = ApplyTypeMapping(item, typeMapping);
Expand Down
8 changes: 8 additions & 0 deletions src/EFCore/Properties/CoreStrings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/EFCore/Properties/CoreStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@
<data name="TranslationFailed" xml:space="preserve">
<value>The LINQ expression '{expression}' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to either AsEnumerable(), AsAsyncEnumerable(), ToList(), or ToListAsync(). See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.</value>
</data>
<data name="QueryFailed" xml:space="preserve">
<value>Processing of the LINQ expression '{expression}' by '{visitor}' failed. This may indicate either a bug or a limitation in EF Core. See https://go.microsoft.com/fwlink/?linkid=2101433 for more detailed information.</value>
</data>
<data name="ModelNotFinalized" xml:space="preserve">
<value>The model must be finalized before '{method}' can be used. Ensure that either 'OnModelCreating' has completed or, if using a stand-alone 'ModelBuilder', that 'FinalizeModel' has been called.</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ protected virtual Expression VisitSelectMethodCall(MethodCallExpression methodCa
? methodCallExpression.Update(null, new[] { newSource, Unwrap(Visit(arguments[1])) })
: arguments.Count == 3
? methodCallExpression.Update(null, new[] { newSource, Unwrap(Visit(arguments[1])), Unwrap(Visit(arguments[2])) })
: throw new InvalidOperationException(CoreStrings.TranslationFailed(methodCallExpression.Print()));
: throw new InvalidOperationException(CoreStrings.QueryFailed(methodCallExpression.Print(), GetType().Name));
}

MethodCallExpression newMethodCall;
Expand Down Expand Up @@ -562,7 +562,7 @@ protected virtual Expression VisitSelectMethodCall(MethodCallExpression methodCa
: (Expression)newMethodCall;
}

throw new InvalidOperationException(CoreStrings.TranslationFailed(methodCallExpression.Print()));
throw new InvalidOperationException(CoreStrings.QueryFailed(methodCallExpression.Print(), GetType().Name));
}

protected virtual Expression VisitJoinMethodCall(MethodCallExpression methodCallExpression)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,31 +183,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
.VerifyCollectionSelector(
groupJoinResultSelectorBody, groupJoinResultSelector.Parameters[1]);

if (correlatedCollectionSelector)
{
// See #17236
throw new InvalidOperationException(CoreStrings.TranslationFailed(
outerKeySelector.Print() + "; " + innerKeySelector.Print() + "; " + groupJoinResultSelector.Print()));

//var outerParameter = outerKeySelector.Parameters[0];
//var innerParameter = innerKeySelector.Parameters[0];
//var correlationPredicate = Expression.Equal(
// outerKeySelector.Body,
// innerKeySelector.Body);

//inner = Expression.Call(
// _whereMethodInfo.MakeGenericMethod(inner.Type.TryGetSequenceType()),
// inner,
// Expression.Quote(Expression.Lambda(correlationPredicate, innerParameter)));

//inner = ReplacingExpressionVisitor.Replace(
// groupJoinResultSelector.Parameters[1],
// inner,
// groupJoinResultSelectorBody);

//inner = Expression.Quote(Expression.Lambda(inner, outerParameter));
}
else
if (!correlatedCollectionSelector)
{
inner = ReplacingExpressionVisitor.Replace(
groupJoinResultSelector.Parameters[1],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ when QueryableMethods.IsSumWithSelector(method):
return ProcessDefaultIfEmpty(source);

default:
throw new InvalidOperationException(CoreStrings.TranslationFailed(methodCallExpression.Print()));
throw new InvalidOperationException(CoreStrings.QueryFailed(methodCallExpression.Print(), GetType().Name));
}
}
else if (firstArgument is MaterializeCollectionNavigationExpression materializeCollectionNavigationExpression
Expand All @@ -536,7 +536,7 @@ when QueryableMethods.IsSumWithSelector(method):
return new NavigationExpansionExpression(methodCallExpression, currentTree, currentTree, parameterName);
}

throw new InvalidOperationException(CoreStrings.TranslationFailed(methodCallExpression.Print()));
throw new InvalidOperationException(CoreStrings.QueryFailed(methodCallExpression.Print(), GetType().Name));
}

if (method.IsGenericMethod
Expand Down Expand Up @@ -797,7 +797,7 @@ private Expression ProcessSelectMany(
return new NavigationExpansionExpression(newSource, currentTree, pendingSelector, parameterName);
}

throw new InvalidOperationException(CoreStrings.TranslationFailed(collectionSelector.Print()));
throw new InvalidOperationException(CoreStrings.QueryFailed(collectionSelector.Print(), GetType().Name));
}

private void ApplyPendingOrderings(NavigationExpansionExpression source)
Expand Down
Loading

0 comments on commit 9fc67e2

Please sign in to comment.