Skip to content

Commit

Permalink
Query: Throw for unknown method encountered in QueryableMethodTranslator
Browse files Browse the repository at this point in the history
Except for the subquery case
This visitor should only translate methods on Queryable so it should not do base eval for others.
All other methods should be passed through SqlTranslator (as they appear inside a lambda)
For subquery, we don't want to throw since we don't know if the subquery has client methods or not (projection case)
This is required for supporting collections/single non-scalar in projection.
  • Loading branch information
smitpatel committed Jun 27, 2019
1 parent 73e8dc7 commit 8c547e2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public CosmosQueryableMethodTranslatingExpressionVisitor(
ISqlExpressionFactory sqlExpressionFactory,
IMemberTranslatorProvider memberTranslatorProvider,
IMethodCallTranslatorProvider methodCallTranslatorProvider)
: base(subquery: false)
{
_model = model;
_sqlExpressionFactory = sqlExpressionFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class InMemoryQueryableMethodTranslatingExpressionVisitor : QueryableMeth
private readonly IModel _model;

public InMemoryQueryableMethodTranslatingExpressionVisitor(IModel model)
: base(subquery: false)
{
_expressionTranslator = new InMemoryExpressionTranslatingExpressionVisitor();
_projectionBindingExpressionVisitor = new InMemoryProjectionBindingExpressionVisitor(_expressionTranslator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public RelationalQueryableMethodTranslatingExpressionVisitor(
IModel model,
IRelationalSqlTranslatingExpressionVisitorFactory relationalSqlTranslatingExpressionVisitorFactory,
ISqlExpressionFactory sqlExpressionFactory)
: base(subquery: false)
{
_sqlTranslator = relationalSqlTranslatingExpressionVisitorFactory.Create(model, this);
_projectionBindingExpressionVisitor = new RelationalProjectionBindingExpressionVisitor(this, _sqlTranslator);
Expand All @@ -39,6 +40,7 @@ private RelationalQueryableMethodTranslatingExpressionVisitor(
IModel model,
RelationalSqlTranslatingExpressionVisitor sqlTranslator,
ISqlExpressionFactory sqlExpressionFactory)
: base(subquery: true)
{
_model = model;
_sqlTranslator = sqlTranslator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ namespace Microsoft.EntityFrameworkCore.Query.Pipeline
{
public abstract class QueryableMethodTranslatingExpressionVisitor : ExpressionVisitor
{
private readonly bool _subquery;

protected QueryableMethodTranslatingExpressionVisitor(bool subquery)
{
_subquery = subquery;
}

protected override Expression VisitConstant(ConstantExpression constantExpression)
=> constantExpression.IsEntityQueryable()
? CreateShapedQueryExpression(((IQueryable)constantExpression.Value).ElementType)
Expand Down Expand Up @@ -424,8 +431,6 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
break;
}
}

throw new NotImplementedException("Unhandled method: " + methodCallExpression.Method.Name);
}

// TODO: Skip ToOrderedQueryable method. See Issue#15591
Expand All @@ -435,7 +440,9 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
return Visit(methodCallExpression.Arguments[0]);
}

return base.VisitMethodCall(methodCallExpression);
return _subquery
? (Expression)null
: throw new NotImplementedException("Unhandled method: " + methodCallExpression.Method.Name);
}

protected Type CreateTransparentIdentifierType(Type outerType, Type innerType)
Expand Down

0 comments on commit 8c547e2

Please sign in to comment.