Skip to content

Commit

Permalink
Query: Throw better exception message for client eval
Browse files Browse the repository at this point in the history
Resolves #17387
  • Loading branch information
smitpatel committed Sep 3, 2019
1 parent 14c8075 commit a028aa1
Show file tree
Hide file tree
Showing 18 changed files with 493 additions and 381 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,21 +115,15 @@ protected override ShapedQueryExpression CreateShapedQueryExpression(Type elemen
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
protected override ShapedQueryExpression TranslateAll(ShapedQueryExpression source, LambdaExpression predicate)
{
throw new InvalidOperationException(CoreStrings.TranslationFailed(predicate.Print()));
}
protected override ShapedQueryExpression TranslateAll(ShapedQueryExpression source, LambdaExpression predicate) => null;

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
protected override ShapedQueryExpression TranslateAny(ShapedQueryExpression source, LambdaExpression predicate)
{
throw new InvalidOperationException(CoreStrings.TranslationFailed(predicate.Print()));
}
protected override ShapedQueryExpression TranslateAny(ShapedQueryExpression source, LambdaExpression predicate) => null;

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand All @@ -144,7 +138,7 @@ protected override ShapedQueryExpression TranslateAverage(ShapedQueryExpression
|| selectExpression.Limit != null
|| selectExpression.Offset != null)
{
throw new InvalidOperationException(CoreStrings.TranslationFailed(selector.Print()));
return null;
}

if (selector != null)
Expand Down Expand Up @@ -185,8 +179,7 @@ protected override ShapedQueryExpression TranslateCast(ShapedQueryExpression sou
/// </summary>
protected override ShapedQueryExpression TranslateConcat(ShapedQueryExpression source1, ShapedQueryExpression source2)
{
throw new InvalidOperationException(CoreStrings.TranslationFailed(
source1.Print() + "; " + source2.Print()));
return null;
}

/// <summary>
Expand All @@ -197,7 +190,7 @@ protected override ShapedQueryExpression TranslateConcat(ShapedQueryExpression s
/// </summary>
protected override ShapedQueryExpression TranslateContains(ShapedQueryExpression source, Expression item)
{
throw new InvalidOperationException(CoreStrings.TranslationFailed(item.Print()));
return null;
}

/// <summary>
Expand All @@ -213,12 +206,16 @@ protected override ShapedQueryExpression TranslateCount(ShapedQueryExpression so
|| selectExpression.Limit != null
|| selectExpression.Offset != null)
{
throw new InvalidOperationException(CoreStrings.TranslationFailed(predicate.Print()));
return null;
}

if (predicate != null)
{
source = TranslateWhere(source, predicate);
if (source == null)
{
return null;
}
}

var translation = _sqlExpressionFactory.ApplyDefaultTypeMapping(
Expand All @@ -244,7 +241,7 @@ protected override ShapedQueryExpression TranslateCount(ShapedQueryExpression so
/// </summary>
protected override ShapedQueryExpression TranslateDefaultIfEmpty(ShapedQueryExpression source, Expression defaultValue)
{
throw new InvalidOperationException(CoreStrings.TranslationFailed(defaultValue.Print()));
return null;
}

/// <summary>
Expand All @@ -268,7 +265,7 @@ protected override ShapedQueryExpression TranslateDistinct(ShapedQueryExpression
/// </summary>
protected override ShapedQueryExpression TranslateElementAtOrDefault(ShapedQueryExpression source, Expression index, bool returnDefault)
{
throw new InvalidOperationException(CoreStrings.TranslationFailed(index.Print()));
return null;
}

/// <summary>
Expand All @@ -279,8 +276,7 @@ protected override ShapedQueryExpression TranslateElementAtOrDefault(ShapedQuery
/// </summary>
protected override ShapedQueryExpression TranslateExcept(ShapedQueryExpression source1, ShapedQueryExpression source2)
{
throw new InvalidOperationException(CoreStrings.TranslationFailed(
source1.Print() + "; " + source2.Print()));
return null;
}

/// <summary>
Expand All @@ -294,6 +290,10 @@ protected override ShapedQueryExpression TranslateFirstOrDefault(ShapedQueryExpr
if (predicate != null)
{
source = TranslateWhere(source, predicate);
if (source == null)
{
return null;
}
}

var selectExpression = (SelectExpression)source.QueryExpression;
Expand All @@ -315,8 +315,7 @@ protected override ShapedQueryExpression TranslateFirstOrDefault(ShapedQueryExpr
/// </summary>
protected override ShapedQueryExpression TranslateGroupBy(ShapedQueryExpression source, LambdaExpression keySelector, LambdaExpression elementSelector, LambdaExpression resultSelector)
{
throw new InvalidOperationException(CoreStrings.TranslationFailed(
keySelector.Print() + "; " + elementSelector.Print() + "; " + resultSelector.Print()));
return null;
}

/// <summary>
Expand All @@ -338,8 +337,7 @@ protected override ShapedQueryExpression TranslateGroupJoin(ShapedQueryExpressio
/// </summary>
protected override ShapedQueryExpression TranslateIntersect(ShapedQueryExpression source1, ShapedQueryExpression source2)
{
throw new InvalidOperationException(CoreStrings.TranslationFailed(
source1.Print() + "; " + source2.Print()));
return null;
}

/// <summary>
Expand All @@ -350,8 +348,7 @@ protected override ShapedQueryExpression TranslateIntersect(ShapedQueryExpressio
/// </summary>
protected override ShapedQueryExpression TranslateJoin(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 All @@ -365,6 +362,10 @@ protected override ShapedQueryExpression TranslateLastOrDefault(ShapedQueryExpre
if (predicate != null)
{
source = TranslateWhere(source, predicate);
if (source == null)
{
return null;
}
}

var selectExpression = (SelectExpression)source.QueryExpression;
Expand All @@ -387,8 +388,7 @@ protected override ShapedQueryExpression TranslateLastOrDefault(ShapedQueryExpre
/// </summary>
protected override ShapedQueryExpression TranslateLeftJoin(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 All @@ -404,12 +404,16 @@ protected override ShapedQueryExpression TranslateLongCount(ShapedQueryExpressio
|| selectExpression.Limit != null
|| selectExpression.Offset != null)
{
throw new InvalidOperationException(CoreStrings.TranslationFailed(predicate.Print()));
return null;
}

if (predicate != null)
{
source = TranslateWhere(source, predicate);
if (source == null)
{
return null;
}
}

var translation = _sqlExpressionFactory.ApplyDefaultTypeMapping(
Expand Down Expand Up @@ -439,7 +443,7 @@ protected override ShapedQueryExpression TranslateMax(ShapedQueryExpression sour
|| selectExpression.Limit != null
|| selectExpression.Offset != null)
{
throw new InvalidOperationException(CoreStrings.TranslationFailed(selector.Print()));
return null;
}

if (selector != null)
Expand Down Expand Up @@ -467,7 +471,7 @@ protected override ShapedQueryExpression TranslateMin(ShapedQueryExpression sour
|| selectExpression.Limit != null
|| selectExpression.Offset != null)
{
throw new InvalidOperationException(CoreStrings.TranslationFailed(selector.Print()));
return null;
}

if (selector != null)
Expand All @@ -490,7 +494,7 @@ protected override ShapedQueryExpression TranslateMin(ShapedQueryExpression sour
/// </summary>
protected override ShapedQueryExpression TranslateOfType(ShapedQueryExpression source, Type resultType)
{
throw new InvalidOperationException(CoreStrings.TranslationFailed(source.Print()));
return null;
}

/// <summary>
Expand All @@ -509,7 +513,7 @@ protected override ShapedQueryExpression TranslateOrderBy(ShapedQueryExpression
return source;
}

throw new InvalidOperationException(CoreStrings.TranslationFailed(keySelector.Print()));
return null;
}

/// <summary>
Expand All @@ -520,7 +524,7 @@ protected override ShapedQueryExpression TranslateOrderBy(ShapedQueryExpression
/// </summary>
protected override ShapedQueryExpression TranslateReverse(ShapedQueryExpression source)
{
throw new InvalidOperationException(CoreStrings.TranslationFailed(source.Print()));
return null;
}

/// <summary>
Expand All @@ -539,7 +543,7 @@ protected override ShapedQueryExpression TranslateSelect(ShapedQueryExpression s
var selectExpression = (SelectExpression)source.QueryExpression;
if (selectExpression.IsDistinct)
{
throw new InvalidOperationException(CoreStrings.TranslationFailed(selector.Print()));
return null;
}

var newSelectorBody = ReplacingExpressionVisitor.Replace(selector.Parameters.Single(), source.ShaperExpression, selector.Body);
Expand All @@ -558,8 +562,7 @@ protected override ShapedQueryExpression TranslateSelect(ShapedQueryExpression s
/// </summary>
protected override ShapedQueryExpression TranslateSelectMany(ShapedQueryExpression source, LambdaExpression collectionSelector, LambdaExpression resultSelector)
{
throw new InvalidOperationException(CoreStrings.TranslationFailed(
collectionSelector.Print() + "; " + resultSelector.Print()));
return null;
}

/// <summary>
Expand All @@ -570,7 +573,7 @@ protected override ShapedQueryExpression TranslateSelectMany(ShapedQueryExpressi
/// </summary>
protected override ShapedQueryExpression TranslateSelectMany(ShapedQueryExpression source, LambdaExpression selector)
{
throw new InvalidOperationException(CoreStrings.TranslationFailed(selector.Print()));
return null;
}

/// <summary>
Expand All @@ -584,6 +587,10 @@ protected override ShapedQueryExpression TranslateSingleOrDefault(ShapedQueryExp
if (predicate != null)
{
source = TranslateWhere(source, predicate);
if (source == null)
{
return null;
}
}

var selectExpression = (SelectExpression)source.QueryExpression;
Expand Down Expand Up @@ -615,7 +622,7 @@ protected override ShapedQueryExpression TranslateSkip(ShapedQueryExpression sou
return source;
}

throw new InvalidOperationException(CoreStrings.TranslationFailed(count.Print()));
return null;
}

/// <summary>
Expand All @@ -626,7 +633,7 @@ protected override ShapedQueryExpression TranslateSkip(ShapedQueryExpression sou
/// </summary>
protected override ShapedQueryExpression TranslateSkipWhile(ShapedQueryExpression source, LambdaExpression predicate)
{
throw new InvalidOperationException(CoreStrings.TranslationFailed(predicate.Print()));
return null;
}

/// <summary>
Expand All @@ -642,7 +649,7 @@ protected override ShapedQueryExpression TranslateSum(ShapedQueryExpression sour
|| selectExpression.Limit != null
|| selectExpression.Offset != null)
{
throw new InvalidOperationException(CoreStrings.TranslationFailed(selector.Print()));
return null;
}

if (selector != null)
Expand Down Expand Up @@ -677,7 +684,7 @@ protected override ShapedQueryExpression TranslateTake(ShapedQueryExpression sou
return source;
}

throw new InvalidOperationException(CoreStrings.TranslationFailed(count.Print()));
return null;
}

/// <summary>
Expand All @@ -688,7 +695,7 @@ protected override ShapedQueryExpression TranslateTake(ShapedQueryExpression sou
/// </summary>
protected override ShapedQueryExpression TranslateTakeWhile(ShapedQueryExpression source, LambdaExpression predicate)
{
throw new InvalidOperationException(CoreStrings.TranslationFailed(predicate.Print()));
return null;
}

/// <summary>
Expand All @@ -707,7 +714,7 @@ protected override ShapedQueryExpression TranslateThenBy(ShapedQueryExpression s
return source;
}

throw new InvalidOperationException(CoreStrings.TranslationFailed(keySelector.Print()));
return null;
}

/// <summary>
Expand All @@ -718,8 +725,7 @@ protected override ShapedQueryExpression TranslateThenBy(ShapedQueryExpression s
/// </summary>
protected override ShapedQueryExpression TranslateUnion(ShapedQueryExpression source1, ShapedQueryExpression source2)
{
throw new InvalidOperationException(CoreStrings.TranslationFailed(
source1.Print() + "; " + source2.Print()));
return null;
}

/// <summary>
Expand All @@ -738,7 +744,7 @@ protected override ShapedQueryExpression TranslateWhere(ShapedQueryExpression so
return source;
}

throw new InvalidOperationException(CoreStrings.TranslationFailed(predicate.Print()));
return null;
}

private SqlExpression TranslateExpression(Expression expression)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ protected override Expression VisitExtension(Expression extensionExpression)
}

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

Expand Down
Loading

0 comments on commit a028aa1

Please sign in to comment.