Skip to content

Commit

Permalink
Query: Allow providers to create subquery translating visitor
Browse files Browse the repository at this point in the history
Fixes #17156
  • Loading branch information
smitpatel committed Aug 20, 2019
1 parent 260fad1 commit ba5c3f7
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,31 @@ public CosmosQueryableMethodTranslatingExpressionVisitor(
_projectionBindingExpressionVisitor = new CosmosProjectionBindingExpressionVisitor(_sqlTranslator);
}

/// <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 CosmosQueryableMethodTranslatingExpressionVisitor(
CosmosQueryableMethodTranslatingExpressionVisitor parentVisitor)
: base(parentVisitor.Dependencies, subquery: true)
{
_model = parentVisitor._model;
_sqlExpressionFactory = parentVisitor._sqlExpressionFactory;
_sqlTranslator = parentVisitor._sqlTranslator;
_projectionBindingExpressionVisitor = new CosmosProjectionBindingExpressionVisitor(_sqlTranslator);
}

/// <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 QueryableMethodTranslatingExpressionVisitor CreateSubqueryVisitor()
=> new CosmosQueryableMethodTranslatingExpressionVisitor(this);

/// <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
Expand Down Expand Up @@ -727,7 +752,7 @@ private SqlExpression TranslateLambdaExpression(
return TranslateExpression(lambdaBody);
}

private Expression RemapLambdaBody(Expression shaperBody, LambdaExpression lambdaExpression)
private static Expression RemapLambdaBody(Expression shaperBody, LambdaExpression lambdaExpression)
{
return ReplacingExpressionVisitor.Replace(lambdaExpression.Parameters.Single(), shaperBody, lambdaExpression.Body);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,17 @@ public InMemoryQueryableMethodTranslatingExpressionVisitor(
_model = model;
}

public InMemoryQueryableMethodTranslatingExpressionVisitor(
QueryableMethodTranslatingExpressionVisitorDependencies dependencies,
IModel model,
InMemoryExpressionTranslatingExpressionVisitor expressionTranslator)
: base(dependencies, subquery: true)
protected InMemoryQueryableMethodTranslatingExpressionVisitor(
InMemoryQueryableMethodTranslatingExpressionVisitor parentVisitor)
: base(parentVisitor.Dependencies, subquery: true)
{
_expressionTranslator = expressionTranslator;
_projectionBindingExpressionVisitor = new InMemoryProjectionBindingExpressionVisitor(this, expressionTranslator);
_model = model;
_expressionTranslator = parentVisitor._expressionTranslator;
_projectionBindingExpressionVisitor = new InMemoryProjectionBindingExpressionVisitor(this, _expressionTranslator);
_model = parentVisitor._model;
}

public override ShapedQueryExpression TranslateSubquery(Expression expression)
{
return (ShapedQueryExpression)new InMemoryQueryableMethodTranslatingExpressionVisitor(
Dependencies,
_model,
_expressionTranslator)
.Visit(expression);
}
protected override QueryableMethodTranslatingExpressionVisitor CreateSubqueryVisitor()
=> new InMemoryQueryableMethodTranslatingExpressionVisitor(this);

protected override ShapedQueryExpression CreateShapedQueryExpression(Type elementType)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,16 @@ public RelationalQueryableMethodTranslatingExpressionVisitor(

protected virtual RelationalQueryableMethodTranslatingExpressionVisitorDependencies RelationalDependencies { get; }

private RelationalQueryableMethodTranslatingExpressionVisitor(
QueryableMethodTranslatingExpressionVisitorDependencies dependencies,
RelationalQueryableMethodTranslatingExpressionVisitorDependencies relationalDependencies,
IModel model,
RelationalSqlTranslatingExpressionVisitor sqlTranslator,
WeakEntityExpandingExpressionVisitor weakEntityExpandingExpressionVisitor,
ISqlExpressionFactory sqlExpressionFactory)
: base(dependencies, subquery: true)
protected RelationalQueryableMethodTranslatingExpressionVisitor(
RelationalQueryableMethodTranslatingExpressionVisitor parentVisitor)
: base(parentVisitor.Dependencies, subquery: true)
{
_model = model;
_sqlTranslator = sqlTranslator;
_weakEntityExpandingExpressionVisitor = weakEntityExpandingExpressionVisitor;
_projectionBindingExpressionVisitor = new RelationalProjectionBindingExpressionVisitor(this, sqlTranslator);
_sqlExpressionFactory = sqlExpressionFactory;
RelationalDependencies = parentVisitor.RelationalDependencies;
_model = parentVisitor._model;
_sqlTranslator = parentVisitor._sqlTranslator;
_weakEntityExpandingExpressionVisitor = parentVisitor._weakEntityExpandingExpressionVisitor;
_projectionBindingExpressionVisitor = new RelationalProjectionBindingExpressionVisitor(this, _sqlTranslator);
_sqlExpressionFactory = parentVisitor._sqlExpressionFactory;
}

protected override Expression VisitMethodCall(MethodCallExpression methodCallExpression)
Expand All @@ -73,14 +69,8 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
return base.VisitMethodCall(methodCallExpression);
}

public override ShapedQueryExpression TranslateSubquery(Expression expression)
=> (ShapedQueryExpression)new RelationalQueryableMethodTranslatingExpressionVisitor(
Dependencies,
RelationalDependencies,
_model,
_sqlTranslator,
_weakEntityExpandingExpressionVisitor,
_sqlExpressionFactory).Visit(expression);
protected override QueryableMethodTranslatingExpressionVisitor CreateSubqueryVisitor()
=> new RelationalQueryableMethodTranslatingExpressionVisitor(this);

protected override ShapedQueryExpression CreateShapedQueryExpression(Type elementType)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ public SqliteQueryableMethodTranslatingExpressionVisitor(
{
}

protected SqliteQueryableMethodTranslatingExpressionVisitor(
SqliteQueryableMethodTranslatingExpressionVisitor parentVisitor)
: base(parentVisitor)
{
}

protected override QueryableMethodTranslatingExpressionVisitor CreateSubqueryVisitor()
=> new SqliteQueryableMethodTranslatingExpressionVisitor(this);

protected override ShapedQueryExpression TranslateOrderBy(ShapedQueryExpression source, LambdaExpression keySelector, bool ascending)
{
var translation = base.TranslateOrderBy(source, keySelector, ascending);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,11 @@ private static Expression AccessInnerTransparentField(
return Expression.Field(targetExpression, fieldInfo);
}

public virtual ShapedQueryExpression TranslateSubquery(Expression expression)
=> (ShapedQueryExpression)CreateSubqueryVisitor().Visit(expression);

protected abstract QueryableMethodTranslatingExpressionVisitor CreateSubqueryVisitor();

protected abstract ShapedQueryExpression CreateShapedQueryExpression(Type elementType);
protected abstract ShapedQueryExpression TranslateAll(ShapedQueryExpression source, LambdaExpression predicate);
protected abstract ShapedQueryExpression TranslateAny(ShapedQueryExpression source, LambdaExpression predicate);
Expand Down Expand Up @@ -528,6 +533,5 @@ private static Expression AccessInnerTransparentField(
protected abstract ShapedQueryExpression TranslateThenBy(ShapedQueryExpression source, LambdaExpression keySelector, bool ascending);
protected abstract ShapedQueryExpression TranslateUnion(ShapedQueryExpression source1, ShapedQueryExpression source2);
protected abstract ShapedQueryExpression TranslateWhere(ShapedQueryExpression source, LambdaExpression predicate);
public abstract ShapedQueryExpression TranslateSubquery(Expression expression);
}
}

0 comments on commit ba5c3f7

Please sign in to comment.