Exemple #1
0
        public override bool Equals(object obj)
        {
            SimplePropertyRef simplePropertyRef = obj as SimplePropertyRef;

            if (simplePropertyRef != null && Command.EqualTypes((EdmType)this.m_property.DeclaringType, (EdmType)simplePropertyRef.m_property.DeclaringType))
            {
                return(simplePropertyRef.m_property.Name.Equals(this.m_property.Name));
            }
            return(false);
        }
Exemple #2
0
        private static PropertyRefList GetKeyProperties(md.EntityType entityType)
        {
            var desiredProperties = new PropertyRefList();

            foreach (var p in entityType.KeyMembers)
            {
                var edmP = p as md.EdmProperty;
                PlanCompiler.Assert(edmP != null, "EntityType had non-EdmProperty key member?");
                var pRef = new SimplePropertyRef(edmP);
                desiredProperties.Add(pRef);
            }
            return(desiredProperties);
        }
Exemple #3
0
        private static PropertyRefList GetKeyProperties(EntityType entityType)
        {
            PropertyRefList propertyRefList = new PropertyRefList();

            foreach (EdmMember keyMember in entityType.KeyMembers)
            {
                EdmProperty edmProperty = keyMember as EdmProperty;
                System.Data.Entity.Core.Query.PlanCompiler.PlanCompiler.Assert(edmProperty != null, "EntityType had non-EdmProperty key member?");
                SimplePropertyRef simplePropertyRef = new SimplePropertyRef((EdmMember)edmProperty);
                propertyRefList.Add((PropertyRef)simplePropertyRef);
            }
            return(propertyRefList);
        }
Exemple #4
0
        internal IEnumerable <PropertyRef> GetKeyPropertyRefs()
        {
            EntityTypeBase entityType = (EntityTypeBase)null;
            RefType        refType    = (RefType)null;

            entityType = !TypeHelpers.TryGetEdmType <RefType>(this.m_type, out refType) ? TypeHelpers.GetEdmType <EntityTypeBase>(this.m_type) : refType.ElementType;
            foreach (EdmMember keyMember in entityType.KeyMembers)
            {
                System.Data.Entity.Core.Query.PlanCompiler.PlanCompiler.Assert(keyMember is EdmProperty, "Non-EdmProperty key members are not supported");
                SimplePropertyRef spr = new SimplePropertyRef(keyMember);
                yield return((PropertyRef)spr);
            }
        }
Exemple #5
0
        private void CreateFlattenedRecordType(RootTypeInfo type)
        {
            bool flag = TypeSemantics.IsEntityType(type.Type) && type.ImmediateSubTypes.Count == 0;
            List <KeyValuePair <string, TypeUsage> > keyValuePairList = new List <KeyValuePair <string, TypeUsage> >();
            HashSet <string> stringSet = new HashSet <string>();
            int num = 0;

            foreach (PropertyRef propertyRef in type.PropertyRefList)
            {
                string key = (string)null;
                if (flag)
                {
                    SimplePropertyRef simplePropertyRef = propertyRef as SimplePropertyRef;
                    if (simplePropertyRef != null)
                    {
                        key = simplePropertyRef.Property.Name;
                    }
                }
                if (key == null)
                {
                    key = "F" + num.ToString((IFormatProvider)CultureInfo.InvariantCulture);
                    ++num;
                }
                while (stringSet.Contains(key))
                {
                    key = "F" + num.ToString((IFormatProvider)CultureInfo.InvariantCulture);
                    ++num;
                }
                TypeUsage propertyType = this.GetPropertyType(type, propertyRef);
                keyValuePairList.Add(new KeyValuePair <string, TypeUsage>(key, propertyType));
                stringSet.Add(key);
            }
            type.FlattenedType = TypeHelpers.CreateRowType((IEnumerable <KeyValuePair <string, TypeUsage> >)keyValuePairList);
            IEnumerator <PropertyRef> enumerator = type.PropertyRefList.GetEnumerator();

            foreach (EdmProperty property in type.FlattenedType.Properties)
            {
                if (!enumerator.MoveNext())
                {
                    System.Data.Entity.Core.Query.PlanCompiler.PlanCompiler.Assert(false, "property refs count and flattened type member count mismatch?");
                }
                type.AddPropertyMapping(enumerator.Current, property);
            }
        }
Exemple #6
0
        internal IEnumerable <PropertyRef> GetKeyPropertyRefs()
        {
            md.EntityTypeBase entityType = null;
            md.RefType        refType    = null;
            if (TypeHelpers.TryGetEdmType(m_type, out refType))
            {
                entityType = refType.ElementType;
            }
            else
            {
                entityType = TypeHelpers.GetEdmType <md.EntityTypeBase>(m_type);
            }

            // Walk through the list of keys of the entity type, and find their analogs in the
            // "flattened" type
            foreach (var p in entityType.KeyMembers)
            {
                // Eventually this could be RelationshipEndMember, but currently only properties are suppported as key members
                PlanCompiler.Assert(p is md.EdmProperty, "Non-EdmProperty key members are not supported");
                var spr = new SimplePropertyRef(p);
                yield return(spr);
            }
        }
Exemple #7
0
        private TypeUsage GetPropertyType(RootTypeInfo typeInfo, PropertyRef p)
        {
            TypeUsage   type        = (TypeUsage)null;
            PropertyRef propertyRef = (PropertyRef)null;

            while (p is NestedPropertyRef)
            {
                NestedPropertyRef nestedPropertyRef = (NestedPropertyRef)p;
                p           = nestedPropertyRef.OuterProperty;
                propertyRef = nestedPropertyRef.InnerProperty;
            }
            if (p is TypeIdPropertyRef)
            {
                SimplePropertyRef simplePropertyRef = (SimplePropertyRef)propertyRef;
                type = simplePropertyRef == null ? typeInfo.TypeIdType : this.GetTypeInfo(simplePropertyRef.Property.TypeUsage).RootType.TypeIdType;
            }
            else if (p is EntitySetIdPropertyRef || p is NullSentinelPropertyRef)
            {
                type = this.m_intType;
            }
            else if (p is RelPropertyRef)
            {
                type = ((RelPropertyRef)p).Property.ToEnd.TypeUsage;
            }
            else
            {
                SimplePropertyRef simplePropertyRef = p as SimplePropertyRef;
                if (simplePropertyRef != null)
                {
                    type = Helper.GetModelTypeUsage(simplePropertyRef.Property);
                }
            }
            TypeUsage newType = this.GetNewType(type);

            System.Data.Entity.Core.Query.PlanCompiler.PlanCompiler.Assert(null != newType, "unrecognized property type?");
            return(newType);
        }
        private Node FlattenConstructor(ScalarOp op, Node n)
        {
            PlanCompiler.Assert(
                op.OpType == OpType.NewInstance || op.OpType == OpType.NewRecord || op.OpType == OpType.DiscriminatedNewEntity
                || op.OpType == OpType.NewEntity,
                "unexpected op: " + op.OpType + "?");

            // First visit all my children
            VisitChildren(n);

            // Find the new type corresponding to the type
            var typeInfo = m_typeInfo.GetTypeInfo(op.Type);
            var flatType = typeInfo.FlattenedType;
            var newEntityOp = op as NewEntityBaseOp;

            // Identify the fields
            IEnumerable opFields = null;
            DiscriminatedNewEntityOp discriminatedNewInstanceOp = null;
            if (op.OpType
                == OpType.NewRecord)
            {
                // Get only those fields that I have values for 
                opFields = ((NewRecordOp)op).Properties;
            }
            else if (op.OpType
                     == OpType.DiscriminatedNewEntity)
            {
                // Get all properties projected by the discriminated new instance op
                discriminatedNewInstanceOp = (DiscriminatedNewEntityOp)op;
                opFields = discriminatedNewInstanceOp.DiscriminatorMap.Properties;
            }
            else
            {
                // Children align with structural members of type for a standard NewInstanceOp
                opFields = TypeHelpers.GetAllStructuralMembers(op.Type);
            }

            // Next, walk through each of my field, and flatten out any field
            // that is structured.
            var newFields = new List<md.EdmProperty>();
            var newFieldValues = new List<Node>();

            //
            // NOTE: we expect the type id property and the entityset id properties
            //       to be at the start of the properties collection.
            //
            // Add a typeid property if we need one
            //
            if (typeInfo.HasTypeIdProperty)
            {
                newFields.Add(typeInfo.TypeIdProperty);
                if (null == discriminatedNewInstanceOp)
                {
                    newFieldValues.Add(CreateTypeIdConstant(typeInfo));
                }
                else
                {
                    // first child in DiscriminatedNewInstanceOp is discriminator/typeid
                    var discriminator = n.Children[0];

                    if (null == typeInfo.RootType.DiscriminatorMap)
                    {
                        // if there are multiple sets (or free-floating constructors) for this type
                        // hierarchy, normalize the discriminator value to expose the standard
                        // '0X' style values
                        discriminator = NormalizeTypeDiscriminatorValues(discriminatedNewInstanceOp, discriminator);
                    }

                    newFieldValues.Add(discriminator);
                }
            }

            //
            // Add an entitysetid property if we need one
            //
            if (typeInfo.HasEntitySetIdProperty)
            {
                newFields.Add(typeInfo.EntitySetIdProperty);

                PlanCompiler.Assert(newEntityOp != null, "unexpected optype:" + op.OpType);
                var entitySetIdNode = GetEntitySetIdExpr(typeInfo.EntitySetIdProperty, newEntityOp);

                // Get the entity-set-id of the "current" entityset
                newFieldValues.Add(entitySetIdNode);
            }

            // Add a nullability property if we need one
            if (typeInfo.HasNullSentinelProperty)
            {
                newFields.Add(typeInfo.NullSentinelProperty);
                newFieldValues.Add(CreateNullSentinelConstant());
            }

            //
            // first child of discriminatedNewInstanceOp is the typeId; otherwise, the first child is the first property
            //
            var childrenIndex = null == discriminatedNewInstanceOp ? 0 : 1;

            foreach (md.EdmMember opField in opFields)
            {
                var fieldValue = n.Children[childrenIndex];
                if (TypeUtils.IsStructuredType(md.Helper.GetModelTypeUsage(opField)))
                {
                    // Flatten out nested type
                    var nestedFlatType = m_typeInfo.GetTypeInfo(md.Helper.GetModelTypeUsage(opField)).FlattenedType;

                    // Find offset of opField in top-level flat type
                    var nestedPropertyOffset = typeInfo.RootType.GetNestedStructureOffset(new SimplePropertyRef(opField));

                    foreach (var nestedProperty in nestedFlatType.Properties)
                    {
                        // Try to build up an accessor for this property from the input
                        var nestedPropertyValue = BuildAccessor(fieldValue, nestedProperty);

                        if (null != nestedPropertyValue)
                        {
                            newFields.Add(flatType.Properties[nestedPropertyOffset]);
                            newFieldValues.Add(nestedPropertyValue);
                        }

                        nestedPropertyOffset++;
                    }
                }
                else
                {
                    PropertyRef propRef = new SimplePropertyRef(opField);
                    var outputTypeProp = typeInfo.GetNewProperty(propRef);

                    newFields.Add(outputTypeProp);

                    newFieldValues.Add(fieldValue);
                }

                childrenIndex++;
            }

            //
            // We've now handled all the regular properties. Now, walk through all the rel properties - 
            // obviously, this only applies for the *NewEntityOps
            //
            if (newEntityOp != null)
            {
                foreach (var relProp in newEntityOp.RelationshipProperties)
                {
                    var fieldValue = n.Children[childrenIndex];
                    var nestedFlatType = m_typeInfo.GetTypeInfo(relProp.ToEnd.TypeUsage).FlattenedType;

                    // Find offset of opField in top-level flat type
                    var nestedPropertyOffset = typeInfo.RootType.GetNestedStructureOffset(new RelPropertyRef(relProp));

                    foreach (var nestedProperty in nestedFlatType.Properties)
                    {
                        // Try to build up an accessor for this property from the input
                        var nestedPropertyValue = BuildAccessor(fieldValue, nestedProperty);

                        if (null != nestedPropertyValue)
                        {
                            newFields.Add(flatType.Properties[nestedPropertyOffset]);
                            newFieldValues.Add(nestedPropertyValue);
                        }

                        nestedPropertyOffset++;
                    }
                    childrenIndex++;
                }
            }

            //
            // So, now we have the list of all fields that should make up the 
            // flat type.  Create a new node with them.
            //
            var newOp = m_command.CreateNewRecordOp(typeInfo.FlattenedTypeUsage, newFields);
            var newNode = m_command.CreateNode(newOp, newFieldValues);

            return newNode;
        }
        internal IEnumerable<PropertyRef> GetKeyPropertyRefs()
        {
            md.EntityTypeBase entityType = null;
            md.RefType refType = null;
            if (TypeHelpers.TryGetEdmType(m_type, out refType))
            {
                entityType = refType.ElementType;
            }
            else
            {
                entityType = TypeHelpers.GetEdmType<md.EntityTypeBase>(m_type);
            }

            // Walk through the list of keys of the entity type, and find their analogs in the
            // "flattened" type
            foreach (var p in entityType.KeyMembers)
            {
                // Eventually this could be RelationshipEndMember, but currently only properties are suppported as key members
                PlanCompiler.Assert(p is md.EdmProperty, "Non-EdmProperty key members are not supported");
                var spr = new SimplePropertyRef(p);
                yield return spr;
            }
        }
 private static PropertyRefList GetKeyProperties(md.EntityType entityType)
 {
     var desiredProperties = new PropertyRefList();
     foreach (var p in entityType.KeyMembers)
     {
         var edmP = p as md.EdmProperty;
         PlanCompiler.Assert(edmP != null, "EntityType had non-EdmProperty key member?");
         var pRef = new SimplePropertyRef(edmP);
         desiredProperties.Add(pRef);
     }
     return desiredProperties;
 }