src/Shared/EntityFramework/Core/Query/InternalTrees/OpCopier.cs
// <summary>
// Common copy path for all SetOps
// </summary>
// <param name="op"> The SetOp to Copy (must be one of ExceptOp, IntersectOp, UnionAllOp) </param>
// <param name="n"> The Node that references the Op </param>
// <returns> A copy of the original Node that references a copy of the original Op </returns>
Common copy path for all SetOps
Common copy path for all SetOps
private Node CopySetOp(SetOp op, Node n)
        {
            var children = ProcessChildren(n);
            var leftMap = new VarMap();
            var rightMap = new VarMap();
            foreach (var kv in op.VarMap[0])
            {
                Var outputVar = m_destCmd.CreateSetOpVar(kv.Key.Type);
                SetMappedVar(kv.Key, outputVar);
                leftMap.Add(outputVar, GetMappedVar(kv.Value));
                rightMap.Add(outputVar, GetMappedVar((op.VarMap[1])[kv.Key]));
            }
            SetOp newSetOp = null;
            switch (op.OpType)
            {
                case OpType.UnionAll:
                    {
                        var branchDiscriminator = ((UnionAllOp)op).BranchDiscriminator;
                        if (null != branchDiscriminator)
                        {
                            branchDiscriminator = GetMappedVar(branchDiscriminator);
                        }
                        newSetOp = m_destCmd.CreateUnionAllOp(leftMap, rightMap, branchDiscriminator);
                    }
                    break;
                case OpType.Intersect:
                    {
                        newSetOp = m_destCmd.CreateIntersectOp(leftMap, rightMap);
                    }
                    break;
                case OpType.Except:
                    {
                        newSetOp = m_destCmd.CreateExceptOp(leftMap, rightMap);
                    }
                    break;
                default:
                    {
                        Debug.Assert(false, "Unexpected SetOpType");
                    }
                    break;
            }
            return m_destCmd.CreateNode(newSetOp, children);
        }
private Node CopySetOp ( SetOp op , Node n ) { var children = ProcessChildren ( n ) ; var leftMap = new VarMap ( ) ; var rightMap = new VarMap ( ) ; foreach ( var kv in op . VarMap [ 0 ] ) { Var outputVar = m_destCmd . CreateSetOpVar ( kv . Key . Type ) ; SetMappedVar ( kv . Key , outputVar ) ; leftMap . Add ( outputVar , GetMappedVar ( kv . Value ) ) ; rightMap . Add ( outputVar , GetMappedVar ( ( op . VarMap [ 1 ] ) [ kv . Key ] ) ) ; } SetOp newSetOp = null ; switch ( op . OpType ) { case OpType . UnionAll : { var branchDiscriminator = ( ( UnionAllOp ) op ) . BranchDiscriminator ; if ( null != branchDiscriminator ) { branchDiscriminator = GetMappedVar ( branchDiscriminator ) ; } newSetOp = m_destCmd . CreateUnionAllOp ( leftMap , rightMap , branchDiscriminator ) ; } break ; case OpType . Intersect : { newSetOp = m_destCmd . CreateIntersectOp ( leftMap , rightMap ) ; } break ; case OpType . Except : { newSetOp = m_destCmd . CreateExceptOp ( leftMap , rightMap ) ; } break ; default : { Debug . Assert ( false , " " ) ; } break ; } return m_destCmd . CreateNode ( newSetOp , children ) ; }
Common copy path for all SetOps
Common copy path for all SetOps
// Visit the Node's children and map their Vars // Create a new output Var that is a copy of the original output Var // Add a mapping for the new output var we've just created // Add this output var's entries to the new VarMaps
A copy of the original Node that references a copy of the original Op
A copy of the original Node that references a copy of the original Op
op
SetOp
The SetOp to Copy (must be one of ExceptOp, IntersectOp, UnionAllOp)
The SetOp to Copy ( must be one of ExceptOp IntersectOp UnionAllOp )
n
Node
The Node that references the Op
The Node that references the Op