Exemple #1
0
 private void ExplodeRootStructuredType(RootTypeInfo rootType)
 {
     if (rootType.FlattenedType != null)
     {
         return;
     }
     if (StructuredTypeInfo.NeedsTypeIdProperty((TypeInfo)rootType))
     {
         rootType.AddPropertyRef((PropertyRef)TypeIdPropertyRef.Instance);
         if (rootType.DiscriminatorMap != null)
         {
             rootType.TypeIdKind = TypeIdKind.UserSpecified;
             rootType.TypeIdType = Helper.GetModelTypeUsage(rootType.DiscriminatorMap.DiscriminatorProperty);
         }
         else
         {
             rootType.TypeIdKind = TypeIdKind.Generated;
             rootType.TypeIdType = this.m_stringType;
         }
     }
     if (this.NeedsEntitySetIdProperty((TypeInfo)rootType))
     {
         rootType.AddPropertyRef((PropertyRef)EntitySetIdPropertyRef.Instance);
     }
     if (this.NeedsNullSentinelProperty((TypeInfo)rootType))
     {
         rootType.AddPropertyRef((PropertyRef)NullSentinelPropertyRef.Instance);
     }
     this.ExplodeRootStructuredTypeHelper((TypeInfo)rootType);
     if (TypeSemantics.IsEntityType(rootType.Type))
     {
         this.AddRelProperties((TypeInfo)rootType);
     }
     this.CreateFlattenedRecordType(rootType);
 }
Exemple #2
0
        private void AddEntityTypeToSetEntry(EntityType entityType, EntitySet entitySet)
        {
            EntityTypeBase rootType = StructuredTypeInfo.GetRootType((EntityTypeBase)entityType);
            bool           flag     = true;

            if (entitySet == null)
            {
                flag = false;
            }
            else
            {
                EntitySet entitySet1;
                if (this.m_entityTypeToEntitySetMap.TryGetValue(rootType, out entitySet1) && entitySet1 != entitySet)
                {
                    flag = false;
                }
            }
            if (flag)
            {
                this.m_entityTypeToEntitySetMap[rootType] = entitySet;
            }
            else
            {
                this.m_entityTypeToEntitySetMap[rootType] = (EntitySet)null;
            }
        }
 internal ColumnMapProcessor(VarRefColumnMap columnMap, VarInfo varInfo, StructuredTypeInfo typeInfo)
 {
     m_columnMap = columnMap;
     m_varInfo   = varInfo;
     PlanCompiler.Assert(varInfo.NewVars != null && varInfo.NewVars.Count > 0, "No new Vars specified");
     m_varList  = varInfo.NewVars.GetEnumerator();
     m_typeInfo = typeInfo;
 }
 internal ColumnMapProcessor(VarRefColumnMap columnMap, VarInfo varInfo, StructuredTypeInfo typeInfo)
 {
     m_columnMap = columnMap;
     m_varInfo = varInfo;
     PlanCompiler.Assert(varInfo.NewVars != null && varInfo.NewVars.Count > 0, "No new Vars specified");
     m_varList = varInfo.NewVars.GetEnumerator();
     m_typeInfo = typeInfo;
 }
Exemple #5
0
        internal EntitySet GetEntitySet(EntityTypeBase type)
        {
            EntitySet entitySet;

            if (!this.m_entityTypeToEntitySetMap.TryGetValue(StructuredTypeInfo.GetRootType(type), out entitySet))
            {
                return((EntitySet)null);
            }
            return(entitySet);
        }
Exemple #6
0
 internal ColumnMapProcessor(
     VarRefColumnMap columnMap,
     VarInfo varInfo,
     StructuredTypeInfo typeInfo)
 {
     this.m_columnMap = columnMap;
     this.m_varInfo   = varInfo;
     System.Data.Entity.Core.Query.PlanCompiler.PlanCompiler.Assert(varInfo.NewVars != null && varInfo.NewVars.Count > 0, "No new Vars specified");
     this.m_varList  = (IEnumerator <Var>)varInfo.NewVars.GetEnumerator();
     this.m_typeInfo = typeInfo;
 }
Exemple #7
0
 internal static void Process(
     Command itree,
     HashSet <TypeUsage> referencedTypes,
     HashSet <EntitySet> referencedEntitySets,
     HashSet <EntityType> freeFloatingEntityConstructorTypes,
     Dictionary <EntitySetBase, DiscriminatorMapInfo> discriminatorMaps,
     RelPropertyHelper relPropertyHelper,
     HashSet <string> typesNeedingNullSentinel,
     out StructuredTypeInfo structuredTypeInfo)
 {
     structuredTypeInfo = new StructuredTypeInfo(typesNeedingNullSentinel);
     structuredTypeInfo.Process(itree, referencedTypes, referencedEntitySets, freeFloatingEntityConstructorTypes, discriminatorMaps, relPropertyHelper);
 }
        /// <summary>
        /// The driver routine.
        /// </summary>
        /// <param name="planCompilerState">plan compiler state</param>
        /// <param name="typeInfo">type information about all types/sets referenced in the query</param>
        /// <param name="tvfResultKeys">inferred key columns of tvfs return types</param>
        internal static void Process(
            PlanCompiler planCompilerState,
            out StructuredTypeInfo typeInfo,
            out Dictionary<EdmFunction, EdmProperty[]> tvfResultKeys)
        {
            var preProcessor = new PreProcessor(planCompilerState);
            preProcessor.Process(out tvfResultKeys);

            StructuredTypeInfo.Process(
                planCompilerState.Command,
                preProcessor.m_referencedTypes,
                preProcessor.m_referencedEntitySets,
                preProcessor.m_freeFloatingEntityConstructorTypes,
                preProcessor.m_suppressDiscriminatorMaps ? null : preProcessor.m_discriminatorMaps,
                preProcessor.m_relPropertyHelper,
                preProcessor.m_typesNeedingNullSentinel,
                out typeInfo);
        }
Exemple #9
0
        private void ProcessDiscriminatorMaps(
            Dictionary <EntitySetBase, DiscriminatorMapInfo> discriminatorMaps)
        {
            Dictionary <EntitySetBase, ExplicitDiscriminatorMap> dictionary = (Dictionary <EntitySetBase, ExplicitDiscriminatorMap>)null;

            if (discriminatorMaps != null)
            {
                dictionary = new Dictionary <EntitySetBase, ExplicitDiscriminatorMap>(discriminatorMaps.Count, discriminatorMaps.Comparer);
                foreach (KeyValuePair <EntitySetBase, DiscriminatorMapInfo> discriminatorMap1 in discriminatorMaps)
                {
                    EntitySetBase            key = discriminatorMap1.Key;
                    ExplicitDiscriminatorMap discriminatorMap2 = discriminatorMap1.Value.DiscriminatorMap;
                    if (discriminatorMap2 != null && this.GetEntitySet(StructuredTypeInfo.GetRootType(key.ElementType)) != null)
                    {
                        dictionary.Add(key, discriminatorMap2);
                    }
                }
                if (dictionary.Count == 0)
                {
                    dictionary = (Dictionary <EntitySetBase, ExplicitDiscriminatorMap>)null;
                }
            }
            this.m_discriminatorMaps = dictionary;
        }
        /// <summary>
        ///     Eliminates all structural types from the query
        /// </summary>
        /// <param name="compilerState"> current compiler state </param>
        /// <param name="structuredTypeInfo"> </param>
        /// <param name="tvfResultKeys"> inferred s-space keys for TVFs that are mapped to entities </param>
        internal static void Process(
            PlanCompiler compilerState,
            StructuredTypeInfo structuredTypeInfo,
            Dictionary<md.EdmFunction, md.EdmProperty[]> tvfResultKeys)
        {
#if DEBUG
    //string phase0 = Dump.ToXml(compilerState.Command);
            Validator.Validate(compilerState);
#endif

            // Phase 1: Top-down property pushdown
            Dictionary<Var, PropertyRefList> varPropertyMap;
            Dictionary<Node, PropertyRefList> nodePropertyMap;
            PropertyPushdownHelper.Process(compilerState.Command, out varPropertyMap, out nodePropertyMap);

#if DEBUG
    //string phase1 = Dump.ToXml(compilerState.Command);
            Validator.Validate(compilerState);
#endif

            // Phase 2: actually eliminate nominal types
            var nte = new NominalTypeEliminator(
                compilerState, structuredTypeInfo, varPropertyMap, nodePropertyMap, tvfResultKeys);
            nte.Process();

#if DEBUG
    //string phase2 = Dump.ToXml(compilerState.Command);
            Validator.Validate(compilerState);
#endif

#if DEBUG
    //To avoid garbage collection
    //int size = phase0.Length;
    //size = phase1.Length;
    //size = phase2.Length;
#endif
        }
        private const string PrefixMatchCharacter = "%"; // This is ANSI-SQL defined, but it should probably be configurable.

        #endregion

        #region constructors

        private NominalTypeEliminator(
            PlanCompiler compilerState,
            StructuredTypeInfo typeInfo,
            Dictionary<Var, PropertyRefList> varPropertyMap,
            Dictionary<Node, PropertyRefList> nodePropertyMap,
            Dictionary<md.EdmFunction, md.EdmProperty[]> tvfResultKeys)
        {
            m_compilerState = compilerState;
            m_typeInfo = typeInfo;
            m_varPropertyMap = varPropertyMap;
            m_nodePropertyMap = nodePropertyMap;
            m_varInfoMap = new VarInfoMap();
            m_tvfResultKeys = tvfResultKeys;
            m_typeToNewTypeMap = new Dictionary<md.TypeUsage, md.TypeUsage>(TypeUsageEqualityComparer.Instance);
        }
 // <summary>
 // Process Driver
 // </summary>
 // <param name="referencedTypes"> structured types referenced in the query </param>
 // <param name="referencedEntitySets"> entitysets referenced in the query </param>
 // <param name="freeFloatingEntityConstructorTypes"> entity types that have "free-floating" entity constructors </param>
 // <param name="discriminatorMaps"> information on optimized discriminator patterns for entity sets </param>
 // <param name="relPropertyHelper"> helper for rel properties </param>
 // <param name="typesNeedingNullSentinel"> which types need a null sentinel </param>
 internal static void Process(
     Command itree,
     HashSet<md.TypeUsage> referencedTypes,
     HashSet<md.EntitySet> referencedEntitySets,
     HashSet<md.EntityType> freeFloatingEntityConstructorTypes,
     Dictionary<md.EntitySetBase, DiscriminatorMapInfo> discriminatorMaps,
     RelPropertyHelper relPropertyHelper,
     HashSet<string> typesNeedingNullSentinel,
     out StructuredTypeInfo structuredTypeInfo)
 {
     structuredTypeInfo = new StructuredTypeInfo(typesNeedingNullSentinel);
     structuredTypeInfo.Process(
         itree, referencedTypes, referencedEntitySets, freeFloatingEntityConstructorTypes, discriminatorMaps, relPropertyHelper);
 }
Exemple #13
0
        private bool TryGetDiscriminatorMap(EdmType type, out ExplicitDiscriminatorMap discriminatorMap)
        {
            discriminatorMap = (ExplicitDiscriminatorMap)null;
            EntitySet entitySet;

            if (this.m_discriminatorMaps == null || type.BuiltInTypeKind != BuiltInTypeKind.EntityType || (!this.m_entityTypeToEntitySetMap.TryGetValue(StructuredTypeInfo.GetRootType((EntityTypeBase)type), out entitySet) || entitySet == null))
            {
                return(false);
            }
            return(this.m_discriminatorMaps.TryGetValue((EntitySetBase)entitySet, out discriminatorMap));
        }