Skip to content

Commit

Permalink
[Query] Remove QueryExpression from ProjectionBindingExpression (#15609)
Browse files Browse the repository at this point in the history
Invariant: ProjectionBindingExpression can only appear in ShapedQueryExpression.ShaperExpression and it would always refer to ShapedQueryExpression.QueryExpression
  • Loading branch information
smitpatel authored May 3, 2019
1 parent 1169e6c commit 33c785c
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public override Expression Visit(Expression expression)

_projectionMapping[_projectionMembers.Peek()] = translation;

return new ProjectionBindingExpression(_queryExpression, _projectionMembers.Peek(), expression.Type);
return new ProjectionBindingExpression(_projectionMembers.Peek(), expression.Type);
}

return base.Visit(expression);
Expand All @@ -92,7 +92,7 @@ protected override Expression VisitExtension(Expression extensionExpression)
entityShaperExpression.ValueBufferExpression.ProjectionMember);

return entityShaperExpression.Update(
new ProjectionBindingExpression(_queryExpression, _projectionMembers.Peek(), typeof(ValueBuffer)));
new ProjectionBindingExpression(_projectionMembers.Peek(), typeof(ValueBuffer)));
}

throw new InvalidOperationException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public Expression GetSingleScalarProjection()
_projectionMapping.Clear();
_projectionMapping[new ProjectionMember()] = _valueBufferSlots[0];

return new ProjectionBindingExpression(this, new ProjectionMember(), ServerQueryExpression.Type);
return new ProjectionBindingExpression(new ProjectionMember(), ServerQueryExpression.Type);
}

public Expression BindProperty(Expression projectionExpression, IProperty property)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,9 @@ public class InMemoryShapedQueryExpression : ShapedQueryExpression
public InMemoryShapedQueryExpression(IEntityType entityType)
{
QueryExpression = new InMemoryQueryExpression(entityType);
var resultParameter = Parameter(typeof(InMemoryQueryExpression), "result");
ShaperExpression = new EntityShaperExpression(
entityType,
new ProjectionBindingExpression(
QueryExpression,
new ProjectionMember(),
typeof(ValueBuffer)),
new ProjectionBindingExpression(new ProjectionMember(), typeof(ValueBuffer)),
false);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public override Expression Visit(Expression expression)

_projectionMapping[_projectionMembers.Peek()] = translation ?? throw new InvalidOperationException();

return new ProjectionBindingExpression(_selectExpression, _projectionMembers.Peek(), expression.Type);
return new ProjectionBindingExpression(_projectionMembers.Peek(), expression.Type);
}

return base.Visit(expression);
Expand All @@ -102,7 +102,7 @@ protected override Expression VisitExtension(Expression extensionExpression)
entityShaperExpression.ValueBufferExpression.ProjectionMember);

return entityShaperExpression.Update(
new ProjectionBindingExpression(_selectExpression, _projectionMembers.Peek(), typeof(ValueBuffer)));
new ProjectionBindingExpression(_projectionMembers.Peek(), typeof(ValueBuffer)));
}

throw new InvalidOperationException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ protected override ShapedQueryExpression TranslateAll(ShapedQueryExpression sour
new List<ProjectionExpression>(),
new List<TableExpressionBase>());

source.ShaperExpression = new ProjectionBindingExpression(source.QueryExpression, new ProjectionMember(), typeof(bool));
source.ShaperExpression = new ProjectionBindingExpression(new ProjectionMember(), typeof(bool));

return source;
}
Expand Down Expand Up @@ -99,7 +99,7 @@ protected override ShapedQueryExpression TranslateAny(ShapedQueryExpression sour
projectionMapping,
new List<ProjectionExpression>(),
new List<TableExpressionBase>());
source.ShaperExpression = new ProjectionBindingExpression(source.QueryExpression, new ProjectionMember(), typeof(bool));
source.ShaperExpression = new ProjectionBindingExpression(new ProjectionMember(), typeof(bool));

return source;
}
Expand Down Expand Up @@ -182,7 +182,7 @@ protected override ShapedQueryExpression TranslateContains(ShapedQueryExpression
projectionMapping,
new List<ProjectionExpression>(),
new List<TableExpressionBase>());
source.ShaperExpression = new ProjectionBindingExpression(source.QueryExpression, new ProjectionMember(), typeof(bool));
source.ShaperExpression = new ProjectionBindingExpression(new ProjectionMember(), typeof(bool));

return source;
}
Expand Down Expand Up @@ -216,7 +216,7 @@ protected override ShapedQueryExpression TranslateCount(ShapedQueryExpression so

selectExpression.ClearOrdering();
selectExpression.ApplyProjection(_projectionMapping);
source.ShaperExpression = new ProjectionBindingExpression(selectExpression, new ProjectionMember(), typeof(int));
source.ShaperExpression = new ProjectionBindingExpression(new ProjectionMember(), typeof(int));

return source;
}
Expand Down Expand Up @@ -481,7 +481,7 @@ protected override ShapedQueryExpression TranslateLongCount(ShapedQueryExpressio

selectExpression.ClearOrdering();
selectExpression.ApplyProjection(_projectionMapping);
source.ShaperExpression = new ProjectionBindingExpression(selectExpression, new ProjectionMember(), typeof(long));
source.ShaperExpression = new ProjectionBindingExpression(new ProjectionMember(), typeof(long));

return source;
}
Expand Down Expand Up @@ -812,7 +812,7 @@ private ShapedQueryExpression AggregateResultShaper(

selectExpression.ClearOrdering();

Expression shaper = new ProjectionBindingExpression(selectExpression, new ProjectionMember(), projection.Type);
Expression shaper = new ProjectionBindingExpression(new ProjectionMember(), projection.Type);

if (throwOnNullResult)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ public class RelationalShapedQueryExpression : ShapedQueryExpression
public RelationalShapedQueryExpression(IEntityType entityType)
{
QueryExpression = new SelectExpression(entityType);
var resultParameter = Parameter(typeof(SelectExpression), "result");
ShaperExpression = new EntityShaperExpression(
entityType,
new ProjectionBindingExpression(
QueryExpression,
new ProjectionMember(),
typeof(ValueBuffer)),
false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,7 @@ protected override Expression VisitExtension(Expression extensionExpression)

if (extensionExpression is ProjectionBindingExpression projectionBindingExpression)
{
return ((SelectExpression)projectionBindingExpression.QueryExpression)
.GetProjectionExpression(projectionBindingExpression.ProjectionMember);
return _selectExpression.GetProjectionExpression(projectionBindingExpression.ProjectionMember);
}

if (extensionExpression is NullConditionalExpression nullConditionalExpression)
Expand Down
4 changes: 1 addition & 3 deletions src/EFCore/Query/PipeLine/ProjectionBindingExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ namespace Microsoft.EntityFrameworkCore.Query.Pipeline
{
public class ProjectionBindingExpression : Expression
{
public ProjectionBindingExpression(Expression queryExpression, ProjectionMember projectionMember, Type type)
public ProjectionBindingExpression(ProjectionMember projectionMember, Type type)
{
QueryExpression = queryExpression;
ProjectionMember = projectionMember;
Type = type;
}

public Expression QueryExpression { get; }
public ProjectionMember ProjectionMember { get; }
public override Type Type { get; }
public override ExpressionType NodeType => ExpressionType.Extension;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,6 @@ protected override Expression VisitExtension(Expression node)
if (node is ProjectionBindingExpression projectionBindingExpression)
{
return new ProjectionBindingExpression(
_queryExpression,
projectionBindingExpression.ProjectionMember.ShiftMember(_memberShift),
projectionBindingExpression.Type);
}
Expand Down

0 comments on commit 33c785c

Please sign in to comment.