/// <summary>
        /// EntityColumnMap
        /// </summary>
        /// <param name="columnMap"></param>
        /// <param name="replacementVarMap"></param>
        /// <returns></returns>
        internal override ColumnMap Visit(EntityColumnMap columnMap, VarMap replacementVarMap)
        {
            EntityIdentity newEntityIdentity = VisitEntityIdentity(columnMap.EntityIdentity, replacementVarMap);

            ColumnMap[] fieldList = VisitList(columnMap.Properties, replacementVarMap);
            return(new EntityColumnMap(columnMap.Type, columnMap.Name, fieldList, newEntityIdentity));
        }
Beispiel #2
0
 internal virtual void Visit(EntityColumnMap columnMap, TArgType arg)
 {
     VisitEntityIdentity(columnMap.EntityIdentity, arg);
     foreach (ColumnMap p in columnMap.Properties)
     {
         p.Accept(this, arg);
     }
 }
Beispiel #3
0
 /// <summary>
 /// EntityColumnMap
 /// </summary>
 /// <param name="columnMap"></param>
 /// <param name="dumper"></param>
 /// <returns></returns>
 internal override void Visit(EntityColumnMap columnMap, Dump dumper)
 {
     using (new AutoXml(dumper, "Entity", GetAttributes(columnMap))) {
         using (new AutoXml(dumper, "entityIdentity")) {
             VisitEntityIdentity(columnMap.EntityIdentity, dumper);
         }
         VisitList(columnMap.Properties, dumper);
     }
 }
Beispiel #4
0
        /// <summary>
        /// Creates a column map for the given reader and function mapping.
        /// </summary>
        internal static CollectionColumnMap CreateFunctionImportStructuralTypeColumnMap(DbDataReader storeDataReader, FunctionImportMappingNonComposable mapping, int resultSetIndex, EntitySet entitySet, StructuralType baseStructuralType)
        {
            FunctionImportStructuralTypeMappingKB resultMapping = mapping.GetResultMapping(resultSetIndex);

            Debug.Assert(resultMapping != null);
            if (resultMapping.NormalizedEntityTypeMappings.Count == 0) // no explicit mapping; use default non-polymorphic reader
            {
                // if there is no mapping, create default mapping to root entity type or complex type
                Debug.Assert(!baseStructuralType.Abstract, "mapping loader must verify abstract types have explicit mapping");

                return(CreateColumnMapFromReaderAndType(storeDataReader, baseStructuralType, entitySet, resultMapping.ReturnTypeColumnsRenameMapping));
            }

            // the section below deals with the polymorphic entity type mapping for return type
            EntityType baseEntityType = baseStructuralType as EntityType;

            Debug.Assert(null != baseEntityType, "We should have entity type here");

            // Generate column maps for all discriminators
            ScalarColumnMap[] discriminatorColumns = CreateDiscriminatorColumnMaps(storeDataReader, mapping, resultSetIndex);

            // Generate default maps for all mapped entity types
            var mappedEntityTypes = new HashSet <EntityType>(resultMapping.MappedEntityTypes);

            mappedEntityTypes.Add(baseEntityType); // make sure the base type is represented
            Dictionary <EntityType, TypedColumnMap> typeChoices = new Dictionary <EntityType, TypedColumnMap>(mappedEntityTypes.Count);

            ColumnMap[] baseTypeColumnMaps = null;
            foreach (EntityType entityType in mappedEntityTypes)
            {
                ColumnMap[]     propertyColumnMaps = GetColumnMapsForType(storeDataReader, entityType, resultMapping.ReturnTypeColumnsRenameMapping);
                EntityColumnMap entityColumnMap    = CreateEntityTypeElementColumnMap(storeDataReader, entityType, entitySet, propertyColumnMaps, resultMapping.ReturnTypeColumnsRenameMapping);
                if (!entityType.Abstract)
                {
                    typeChoices.Add(entityType, entityColumnMap);
                }
                if (entityType == baseStructuralType)
                {
                    baseTypeColumnMaps = propertyColumnMaps;
                }
            }

            // NOTE: We don't have a null sentinel here, because the stored proc won't
            //       return one anyway; we'll just presume the data's always there.
            MultipleDiscriminatorPolymorphicColumnMap polymorphicMap = new MultipleDiscriminatorPolymorphicColumnMap(TypeUsage.Create(baseStructuralType), baseStructuralType.Name, baseTypeColumnMaps, discriminatorColumns, typeChoices, (object[] discriminatorValues) => mapping.Discriminate(discriminatorValues, resultSetIndex));
            CollectionColumnMap collection = new SimpleCollectionColumnMap(baseStructuralType.GetCollectionType().TypeUsage, baseStructuralType.Name, polymorphicMap, null, null);

            return(collection);
        }
Beispiel #5
0
        /// <summary>
        /// Build the entityColumnMap from a store datareader, a type and an entitySet and
        /// a list ofproperties.
        /// </summary>
        /// <param name="storeDataReader"></param>
        /// <param name="edmType"></param>
        /// <param name="entitySet"></param>
        /// <param name="propertyColumnMaps"></param>
        /// <returns></returns>
        private static EntityColumnMap CreateEntityTypeElementColumnMap(
            DbDataReader storeDataReader, EdmType edmType, EntitySet entitySet,
            ColumnMap[] propertyColumnMaps, Dictionary <string, FunctionImportReturnTypeStructuralTypeColumnRenameMapping> renameList)
        {
            EntityType entityType = (EntityType)edmType;

            // The tricky part here is
            // that the KeyColumns list must point at the same ColumnMap(s) that
            // the properties list points to, so we build a quick array of
            // ColumnMap(s) that are indexed by their ordinal; then we can walk
            // the list of keyMembers, and find the ordinal in the reader, and
            // pick the same ColumnMap for it.

            // Build the ordinal -> ColumnMap index
            ColumnMap[] ordinalToColumnMap = new ColumnMap[storeDataReader.FieldCount];

            foreach (ColumnMap propertyColumnMap in propertyColumnMaps)
            {
                int ordinal = ((ScalarColumnMap)propertyColumnMap).ColumnPos;
                ordinalToColumnMap[ordinal] = propertyColumnMap;
            }

            // Now build the list of KeyColumns;
            IList <EdmMember> keyMembers = entityType.KeyMembers;

            SimpleColumnMap[] keyColumns = new SimpleColumnMap[keyMembers.Count];

            int keyMemberIndex = 0;

            foreach (EdmMember keyMember in keyMembers)
            {
                int keyOrdinal = GetMemberOrdinalFromReader(storeDataReader, keyMember, edmType, renameList);

                Debug.Assert(keyOrdinal >= 0, "keyMember for entity is not found by name in the data reader?");

                ColumnMap keyColumnMap = ordinalToColumnMap[keyOrdinal];

                Debug.Assert(null != keyColumnMap, "keyMember for entity isn't in properties collection for the entity?");
                keyColumns[keyMemberIndex] = (SimpleColumnMap)keyColumnMap;
                keyMemberIndex++;
            }

            SimpleEntityIdentity entityIdentity = new SimpleEntityIdentity(entitySet, keyColumns);

            EntityColumnMap result = new EntityColumnMap(TypeUsage.Create(edmType), edmType.Name, propertyColumnMaps, entityIdentity);

            return(result);
        }
Beispiel #6
0
 internal abstract TResultType Visit(EntityColumnMap columnMap, TArgType arg);