src/Shared/EntityFramework/Core/Common/EntitySql/SourceScopeEntry.cs
// <summary>
// Rebuild the current scope entry expression as the property chain off the <paramref name="parentVarRef" /> expression.
// Also build
// - <see cref="IGroupExpressionExtendedInfo.GroupVarBasedExpression" /> off the <paramref name="parentGroupVarRef" /> expression;
// - <see cref="IGroupExpressionExtendedInfo.GroupAggBasedExpression" /> off the <paramref name="groupAggRef" /> expression.
// This adjustment is reversable by <see cref="RollbackAdjustmentToGroupVar" />(...).
// </summary>
Rebuild the current scope entry expression as the property chain off the  expression.
Also build
off the  expression;
off the  expression.
This adjustment is reversable by (...).
Rebuild the current scope entry expression as the property chain off the expression . Also build off the expression ; off the expression . This adjustment is reversable by ( ... ) .
internal void AdjustToGroupVar(
            DbVariableReferenceExpression parentVarRef, DbVariableReferenceExpression parentGroupVarRef,
            DbVariableReferenceExpression groupAggRef)
        {
            Debug.Assert(_groupVarBasedExpression == null, "_groupVarBasedExpression == null");
            Debug.Assert(_groupAggBasedExpression == null, "_groupAggBasedExpression == null");
             Let's assume this entry represents variable "x" in the following query:
                  select x, y, z from {1, 2} as x join {2, 3} as y on x = y join {3, 4} as z on y = z
             In this case _propRefs contains x._##join0._##join1 and the corresponding input expression looks like this:
                 |_Input : '_##join1'
                 | |_InnerJoin
                 |   |_Left : '_##join0'
                 |   | |_InnerJoin
                 |   |   |_Left : 'x'
                 |   |   |_Right : 'y'
                 |   |_Right : 'z'
             When we start processing a group by, like in this query:
                  select k1, k2, k3 from {1, 2} as x join {2, 3} as y on x = y join {3, 4} as z on y = z group by x as k1, y as k2, z as k3
             we are switching to the following input expression:
                 |_Input : '_##geb2', '_##group3'
                 | |_InnerJoin
                 |   |_Left : '_##join0'
                 |   | |_InnerJoin
                 |   |   |_Left : 'x'
                 |   |   |_Right : 'y'
                 |   |_Right : 'z'
             where _##join1 is replaced by _##geb2 for the regular expression and by _##group3 for the group var based expression.
             So the switch, or the adjustment, is done by 
                  a. replacing _##join1 with _##geb2 in _propRefs and rebuilding the regular expression accordingly to get
                     the following property chain: _##geb2._##join1.x
                  b. building a group var based expression using _##group3 instead of _##geb2 to get
                     the following property chain: _##group3._##join1.x
             Rebuild ScopeEntry.Expression using the new parent var.
            ReplaceParentVar(parentVarRef);
             Build the GroupVarBasedExpression and GroupAggBasedExpression, 
             take into account that parentVarRef has already been added to the _propRefs in the AdjustToParentVar(...) call, so ignore it.
            _groupVarBasedExpression = parentGroupVarRef;
            _groupAggBasedExpression = groupAggRef;
            if (_propRefs != null)
            {
                for (var i = _propRefs.Count - 2 ; i >= 0; --i)
                {
                    _groupVarBasedExpression = _groupVarBasedExpression.Property(_propRefs[i]);
                    _groupAggBasedExpression = _groupAggBasedExpression.Property(_propRefs[i]);
                }
            }
        }
internal void AdjustToGroupVar ( DbVariableReferenceExpression parentVarRef , DbVariableReferenceExpression parentGroupVarRef , DbVariableReferenceExpression groupAggRef ) { Debug . Assert ( _groupVarBasedExpression == null , " " ) ; Debug . Assert ( _groupAggBasedExpression == null , " " ) ; ReplaceParentVar ( parentVarRef ) ; _groupVarBasedExpression = parentGroupVarRef ; _groupAggBasedExpression = groupAggRef ; if ( _propRefs != null ) { for ( var i = _propRefs . Count - 2 ; i >= 0 ; -- i ) { _groupVarBasedExpression = _groupVarBasedExpression . Property ( _propRefs [ i ] ) ; _groupAggBasedExpression = _groupAggBasedExpression . Property ( _propRefs [ i ] ) ; } } }
Rebuild the current scope entry expression as the property chain off the  expression.
Rebuild the current scope entry expression as the property chain off the expression .
// Adjustment is not reentrant. // // Let's assume this entry represents variable "x" in the following query: //      select x, y, z from {1, 2} as x join {2, 3} as y on x = y join {3, 4} as z on y = z // In this case _propRefs contains x._##join0._##join1 and the corresponding input expression looks like this: //     |_Input : '_##join1' //     | |_InnerJoin //     |   |_Left : '_##join0' //     |   | |_InnerJoin //     |   |   |_Left : 'x' //     |   |   |_Right : 'y' //     |   |_Right : 'z' // When we start processing a group by, like in this query: //      select k1, k2, k3 from {1, 2} as x join {2, 3} as y on x = y join {3, 4} as z on y = z group by x as k1, y as k2, z as k3 // we are switching to the following input expression: //     |_Input : '_##geb2', '_##group3' //     | |_InnerJoin //     |   |_Left : '_##join0' //     |   | |_InnerJoin //     |   |   |_Left : 'x' //     |   |   |_Right : 'y' //     |   |_Right : 'z' // where _##join1 is replaced by _##geb2 for the regular expression and by _##group3 for the group var based expression. // So the switch, or the adjustment, is done by  //      a. replacing _##join1 with _##geb2 in _propRefs and rebuilding the regular expression accordingly to get //         the following property chain: _##geb2._##join1.x //      b. building a group var based expression using _##group3 instead of _##geb2 to get //         the following property chain: _##group3._##join1.x // // // Rebuild ScopeEntry.Expression using the new parent var. // // // Build the GroupVarBasedExpression and GroupAggBasedExpression,  // take into account that parentVarRef has already been added to the _propRefs in the AdjustToParentVar(...) call, so ignore it. // /*ignore the parentVarRef*/
parentVarRef
DbVariableReferenceExpression
parentGroupVarRef
DbVariableReferenceExpression
groupAggRef
DbVariableReferenceExpression