Repository navigation
Conversation
|
@tuespetre, |
smitpatel
left a comment
There was a problem hiding this comment.
Add a test where subquery tries to bind with outer qmv which has client projection.
| /// An Expression. | ||
| /// </returns> | ||
| protected override Expression VisitMethodCall(MethodCallExpression methodCallExpression) | ||
| protected override Expression VisitMethodCall(MethodCallExpression node) |
| /// An Expression. | ||
| /// </returns> | ||
| protected override Expression VisitMember(MemberExpression expression) | ||
| protected override Expression VisitMember(MemberExpression node) |
There was a problem hiding this comment.
change to memberExpression
There was a problem hiding this comment.
change to memberExpression or revert to expression?
| } | ||
|
|
||
| if (aliasExpression == null) | ||
| private Expression TryBindQuerySourcePropertyExpression(MemberExpression expression) |
There was a problem hiding this comment.
Is this method being used elsewhere? If not then we don't need to create this method.
There was a problem hiding this comment.
There are several other methods (even in this class) that are only used in one place. I feel that the readability was greatly improved by making this into its own method:
return TryBindAliasExpression(node, (visitor, binder)
=> visitor.BindMemberExpression(node, binder))
?? TryBindQuerySourcePropertyExpression(node)
?? _queryModelVisitor.BindMemberToOuterQueryParameter(node);
Additionally, this method can be expanded on (for instance, to add support for translating access of a grouping key.)
| { | ||
| var parentSelectExpression = ParentQueryModelVisitor?.TryGetQuery(querySource); | ||
| if (parentSelectExpression != null) | ||
| var ancestor = ParentQueryModelVisitor; |
There was a problem hiding this comment.
variable name -> outerQueryModelVisitor
| private ParameterExpression BindPropertyToOuterParameter(IQuerySource querySource, IProperty property, bool isMemberExpression) | ||
| { | ||
| if (querySource != null && _canBindPropertyToOuterParameter) | ||
| if (querySource != null && _canBindPropertyToOuterParameter && ParentQueryModelVisitor != null) |
There was a problem hiding this comment.
remove null check on qmv
| var parentSelectExpression = ParentQueryModelVisitor?.TryGetQuery(querySource); | ||
| if (parentSelectExpression != null) | ||
| var ancestor = ParentQueryModelVisitor; | ||
| SelectExpression outerQuery = null; |
There was a problem hiding this comment.
var name -> outerSelectExpression
| var ancestor = ParentQueryModelVisitor; | ||
| SelectExpression outerQuery = null; | ||
|
|
||
| do |
There was a problem hiding this comment.
Remove do part of loop by assigning values when declaring variables.
| var column = _relationalAnnotationProvider.For(property).ColumnName; | ||
| var table = selectExpression.GetTableForQuerySource(querySource); | ||
|
|
||
| return new AliasExpression(new ColumnExpression(column, property, table)); |
There was a problem hiding this comment.
There was a problem hiding this comment.
Inline in the sense, you don't need to declare variables for column & table just put them directly in constructor since they are not being used.
| } | ||
|
|
||
| var ancestor = _queryModelVisitor.ParentQueryModelVisitor; | ||
| var canBindToAncestor = _queryModelVisitor.CanBindToParentQueryModel; |
There was a problem hiding this comment.
You may not be able to bind to parent query model visitor if it requires client projection.
There was a problem hiding this comment.
CanBindToParentQueryModel should never be true if the parent qmv requires client projection.
There was a problem hiding this comment.
Can you point me to the place where we are setting that flag appropriately?
There was a problem hiding this comment.
The flag is set by RelationalQueryModelVisitor.VisitSubQueryModel, which is called in RelationalQueryModelVisitor.LiftSubQuery and SqlTranslatingExpressionVisitor.VisitSubQuery.
There was a problem hiding this comment.
FWIW, When a new query model visitor is created, the flag is set to false. So in the case of client projections we create the qmv in ProjectExpressionVisitor which would be called for client projections only.
| /// </summary> | ||
| /// <value> | ||
| /// true if the query model visitor can bind to its parent's properties, false if not. | ||
| /// </value> |
There was a problem hiding this comment.
no need to set to false. Its default
| qmv => qmv.BindMemberExpression(expression, CreateAliasedColumnExpressionCore)); | ||
| } | ||
| return TryBindAliasExpression(node, (visitor, binder) | ||
| => visitor.BindMemberExpression(node, binder)) |
There was a problem hiding this comment.
This is actually a closure rather than a Func since you are passing value of node into the lambda expression. If you look at the function TryBindAliasExpression then you will see the first parameter is never used in its method body. We don't want to create a closure here. Instead change this lambda to take the node as argument and pass the node to it in TryBindAliasExpression
|
Looks good. |
e7e61af to
520ac6b
Compare
|
🆙📅 |
|
|
||
| return expression | ||
| ?? _queryModelVisitor.BindMethodToOuterQueryParameter(methodCallExpression); | ||
| return TryBindAliasExpression(methodCallExpression, (e, visitor, binder) |
| var newExpression = Visit(expression.Expression); | ||
|
|
||
| if (newExpression != null | ||
| if (newExpression != null |
There was a problem hiding this comment.
huh, wonder why Visual Studio diff didn't show that
| _queryModelVisitor.ParentQueryModelVisitor, | ||
| qmv => qmv.BindMemberExpression(expression, CreateAliasedColumnExpressionCore)); | ||
| } | ||
| return TryBindAliasExpression(expression, (e, visitor, binder) |
| } | ||
|
|
||
| if (aliasExpression == null) | ||
| private Expression TryBindQuerySourcePropertyExpression(MemberExpression expression) |
520ac6b to
d25427b
Compare
|
🆙📅 |
| return binder(queryModelVisitor) | ||
| ?? TryBindParentExpression(queryModelVisitor.ParentQueryModelVisitor, binder); | ||
| } | ||
| var ancestor = _queryModelVisitor.ParentQueryModelVisitor; |
There was a problem hiding this comment.
can we move away from this variable name. ancestor does not specify ancestor of what particularly.
Better name would be outerQueryModelVisitor (since its not direct parent always)
There was a problem hiding this comment.
Done (also changed canBindtoAncestor to canBindToOuterQueryModelVisitor)
| private static AliasExpression TryBindParentExpression( | ||
| RelationalQueryModelVisitor queryModelVisitor, | ||
| Func<RelationalQueryModelVisitor, AliasExpression> binder) | ||
| private Expression TryBindAliasExpression<TExpression>( |
There was a problem hiding this comment.
Do we need generics here? Does a simple Expression work?
Probably won't work as binder methods are type specific.
There was a problem hiding this comment.
Generic due to MemberExpression vs. MethodCallExpression
There was a problem hiding this comment.
function name TryBindMemberOrMethodToAliasExpression?
d25427b to
5d33173
Compare
|
Can you add some test around improved binding? Multi-level queries which can be bound with outer select expression through alias expression and through parameter. |
| property, | ||
| selectExpression.GetTableForQuerySource(querySource))); | ||
|
|
||
| var bound = binder(sourceExpression, _queryModelVisitor, (property, querySource, selectExpression) => |
5d33173 to
7bea268
Compare
|
@smitpatel working on tests. |
|
🆙📅 Added some tests and also a fix for an error that was revealed by the tests. Did in a separate commit so you can see the isolated change. |
|
|
||
| private const string OuterQueryParameterNamePrefix = @"_outer_"; | ||
|
|
||
| private readonly Dictionary<string, Expression> _boundParameters = new Dictionary<string, Expression>(); |
There was a problem hiding this comment.
Can we name it injectedParameters?
smitpatel
left a comment
There was a problem hiding this comment.
Squash-rebase on latest dev 👍
b03bae8 to
3d16914
Compare
|
🏁 done |
|
@tuespetre - QueryInMemoryTests are failing. |
| /// the subquery can be lifted. | ||
| /// </summary> | ||
| /// <param name="subQueryModelVisitor"> The query model visitor for the subquery being lifted. </param> | ||
| public void LiftInjectedParameters(RelationalQueryModelVisitor subQueryModelVisitor) |
There was a problem hiding this comment.
add virtual, NotNull annotation and null check on parameter
|
Oops, hadn't thought to run those before pushing. (What happened to the Travis logs BTW?) |
3d16914 to
40b1b43
Compare
|
🆙📅 fixed the tests (needed to change from |
fff887a to
18b4d4c
Compare
|
Merged via 08bdfc9 |
This is a much smaller, less radical version of #7663 that brings only enhancements (no regressions) to the plate.