Exemplo n.º 1
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);
            }
        }
        private void CreateFlattenedRecordType(RootTypeInfo type)
        {
            //
            // If this type corresponds to an entity type, and that entity type
            // has no subtypes, and that that entity type has no complex properties
            // then simply use the name from that property
            //
            bool usePropertyNamesFromUnderlyingType;

            if (md.TypeSemantics.IsEntityType(type.Type)
                &&
                type.ImmediateSubTypes.Count == 0)
            {
                usePropertyNamesFromUnderlyingType = true;
            }
            else
            {
                usePropertyNamesFromUnderlyingType = false;
            }

            // Build the record type
            var fieldList   = new List <KeyValuePair <string, md.TypeUsage> >();
            var fieldNames  = new HashSet <string>();
            var nextFieldId = 0;

            foreach (var p in type.PropertyRefList)
            {
                string fieldName = null;
                if (usePropertyNamesFromUnderlyingType)
                {
                    var simpleP = p as SimplePropertyRef;
                    if (simpleP != null)
                    {
                        fieldName = simpleP.Property.Name;
                    }
                }

                if (fieldName == null)
                {
                    fieldName = "F" + nextFieldId.ToString(CultureInfo.InvariantCulture);
                    nextFieldId++;
                }

                // Deal with collisions
                while (fieldNames.Contains(fieldName))
                {
                    fieldName = "F" + nextFieldId.ToString(CultureInfo.InvariantCulture);
                    nextFieldId++;
                }

                var propertyType = GetPropertyType(type, p);
                fieldList.Add(new KeyValuePair <string, md.TypeUsage>(fieldName, propertyType));
                fieldNames.Add(fieldName);
            }

            type.FlattenedType = TypeHelpers.CreateRowType(fieldList);

            // Now build up the property map
            var origProps = type.PropertyRefList.GetEnumerator();

            foreach (var p in type.FlattenedType.Properties)
            {
                if (!origProps.MoveNext())
                {
                    PlanCompiler.Assert(false, "property refs count and flattened type member count mismatch?");
                }
                type.AddPropertyMapping(origProps.Current, p);
            }
        }
        private void CreateFlattenedRecordType(RootTypeInfo type)
        {
            //
            // If this type corresponds to an entity type, and that entity type
            // has no subtypes, and that that entity type has no complex properties
            // then simply use the name from that property
            //
            bool usePropertyNamesFromUnderlyingType;
            if (md.TypeSemantics.IsEntityType(type.Type)
                &&
                type.ImmediateSubTypes.Count == 0)
            {
                usePropertyNamesFromUnderlyingType = true;
            }
            else
            {
                usePropertyNamesFromUnderlyingType = false;
            }

            // Build the record type
            var fieldList = new List<KeyValuePair<string, md.TypeUsage>>();
            var fieldNames = new HashSet<string>();
            var nextFieldId = 0;
            foreach (var p in type.PropertyRefList)
            {
                string fieldName = null;
                if (usePropertyNamesFromUnderlyingType)
                {
                    var simpleP = p as SimplePropertyRef;
                    if (simpleP != null)
                    {
                        fieldName = simpleP.Property.Name;
                    }
                }

                if (fieldName == null)
                {
                    fieldName = "F" + nextFieldId.ToString(CultureInfo.InvariantCulture);
                    nextFieldId++;
                }

                // Deal with collisions
                while (fieldNames.Contains(fieldName))
                {
                    fieldName = "F" + nextFieldId.ToString(CultureInfo.InvariantCulture);
                    nextFieldId++;
                }

                var propertyType = GetPropertyType(type, p);
                fieldList.Add(new KeyValuePair<string, md.TypeUsage>(fieldName, propertyType));
                fieldNames.Add(fieldName);
            }

            type.FlattenedType = TypeHelpers.CreateRowType(fieldList);

            // Now build up the property map
            var origProps = type.PropertyRefList.GetEnumerator();
            foreach (var p in type.FlattenedType.Properties)
            {
                if (!origProps.MoveNext())
                {
                    PlanCompiler.Assert(false, "property refs count and flattened type member count mismatch?");
                }
                type.AddPropertyMapping(origProps.Current, p);
            }
        }