Example #1
0
        public override void Visit(TreatOp op, System.Data.Entity.Core.Query.InternalTrees.Node n)
        {
            PropertyRefList propertyRefs = this.GetPropertyRefList(n).Clone();

            propertyRefs.Add((PropertyRef)TypeIdPropertyRef.Instance);
            this.AddPropertyRefs(n.Child0, propertyRefs);
            this.VisitChildren(n);
        }
        /// <summary>
        /// TreatOp handling
        ///
        /// Simply passes down "my" desired properties, and additionally
        /// asks for the TypeID property
        /// </summary>
        /// <param name="op"></param>
        /// <param name="n"></param>
        public override void Visit(TreatOp op, Node n)
        {
            // First find the properties that my parent expects from me
            PropertyRefList pdProps = GetPropertyRefList(n);

            // Push down each of these, and in addition, push down the typeid property
            // to my child
            PropertyRefList childProps = pdProps.Clone();

            childProps.Add(TypeIdPropertyRef.Instance);
            AddPropertyRefs(n.Child0, childProps);
            VisitChildren(n);
        }
        /// <summary>
        ///     TreatOp
        ///     TreatOp(e, T) => case when e.TypeId like TypeIdValue(T) then T else null end
        /// </summary>
        /// <param name="op"> the TreatOp </param>
        /// <param name="n"> the node </param>
        /// <returns> new subtree </returns>
        public override Node Visit(TreatOp op, Node n)
        {
            // First visit all my children
            VisitChildren(n);

            //
            // filter out useless treat operations
            // Treat(subtype-instance as superType)
            //
            var arg = (ScalarOp)n.Child0.Op;
            if (op.IsFakeTreat
                ||
                md.TypeSemantics.IsStructurallyEqual(arg.Type, op.Type)
                ||
                md.TypeSemantics.IsSubTypeOf(arg.Type, op.Type))
            {
                return n.Child0;
            }

            // When we support UDTs
            if (!TypeUtils.IsStructuredType(op.Type))
            {
                return n;
            }

            //
            // First, convert this into a CaseOp:
            //   case when e.TypeId like TypeIdValue then e else null end
            //
            var typeInfo = m_typeInfo.GetTypeInfo(op.Type);
            var likeNode = CreateTypeComparisonOp(n.Child0, typeInfo, false);
            var caseOp = m_command.CreateCaseOp(typeInfo.FlattenedTypeUsage);
            var caseNode = m_command.CreateNode(caseOp, likeNode, n.Child0, CreateNullConstantNode(caseOp.Type));

            //
            // Now "flatten" out this Op into a constructor. But only get the
            // desired properties
            //
            var desiredProperties = m_nodePropertyMap[n];
            var flattenedCaseNode = FlattenCaseOp(caseNode, typeInfo, desiredProperties);
            return flattenedCaseNode;
        }
        /// <summary>
        /// Handler for a TreatOp.
        /// Rewrites the operator if the argument is guaranteed to be of type
        /// op.
        /// </summary>
        /// <param name="op">Current TreatOp</param>
        /// <param name="n">Current subtree</param>
        /// <returns>Current subtree</returns>
        public override Node Visit(TreatOp op, Node n)
        {
            n = base.Visit(op, n);

            // See if TreatOp can be rewritten (if it's not polymorphic)
            if (CanRewriteTypeTest(op.Type.EdmType, n.Child0.Op.Type.EdmType))
            {
                // Return argument directly (if the argument is null, 'treat as' also returns null;
                // if the argument is not null, it's guaranteed to be of the correct type)
                return n.Child0;
            }

            return n;
        }
Example #5
0
        /// <summary>
        /// Copies a TreatOp
        /// </summary>
        /// <param name="op">The Op to Copy</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>
        public override Node Visit(TreatOp op, Node n)
        {
            TreatOp newTreatOp = op.IsFakeTreat ? m_destCmd.CreateFakeTreatOp(op.Type) : m_destCmd.CreateTreatOp(op.Type);

            return(CopyDefault(newTreatOp, n));
        }
 /// <summary>
 ///     Visitor pattern method for TreatOp
 /// </summary>
 /// <param name="op"> The TreatOp being visited </param>
 /// <param name="n"> The Node that references the Op </param>
 public virtual void Visit(TreatOp op, Node n)
 {
     VisitScalarOpDefault(op, n);
 }
        /// <summary>
        ///     TreatOp handling
        /// 
        ///     Simply passes down "my" desired properties, and additionally
        ///     asks for the TypeID property
        /// </summary>
        /// <param name="op"> </param>
        /// <param name="n"> </param>
        public override void Visit(TreatOp op, Node n)
        {
            // First find the properties that my parent expects from me
            var pdProps = GetPropertyRefList(n);

            // Push down each of these, and in addition, push down the typeid property
            // to my child
            var childProps = pdProps.Clone();
            childProps.Add(TypeIdPropertyRef.Instance);
            AddPropertyRefs(n.Child0, childProps);
            VisitChildren(n);
        }
Example #8
0
 // <summary>
 // Copies a TreatOp
 // </summary>
 // <param name="op"> The Op to Copy </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>
 public override Node Visit(TreatOp op, Node n)
 {
     var newTreatOp = op.IsFakeTreat ? m_destCmd.CreateFakeTreatOp(op.Type) : m_destCmd.CreateTreatOp(op.Type);
     return CopyDefault(newTreatOp, n);
 }