private void CollectUnreachableTypes(Set <EntityType> reachableTypes, out KeyToListMap <EntityType, LineInfo> entityTypes, out KeyToListMap <EntityType, LineInfo> isTypeOfEntityTypes)
        {
            // Collect line infos for types in violation
            entityTypes         = new KeyToListMap <EntityType, LineInfo>(EqualityComparer <EntityType> .Default);
            isTypeOfEntityTypes = new KeyToListMap <EntityType, LineInfo>(EqualityComparer <EntityType> .Default);

            if (reachableTypes.Count == this.MappedEntityTypes.Count)
            {
                // All types are reachable; nothing to check
                return;
            }

            // Find IsTypeOf mappings where no type in hierarchy can generate a row
            foreach (var isTypeOf in m_isTypeOfLineInfos.Keys)
            {
                if (!MetadataHelper.GetTypeAndSubtypesOf(isTypeOf, m_itemCollection, false)
                    .Cast <EntityType>()
                    .Intersect(reachableTypes)
                    .Any())
                {
                    // no type in the hierarchy is reachable...
                    isTypeOfEntityTypes.AddRange(isTypeOf, m_isTypeOfLineInfos.EnumerateValues(isTypeOf));
                }
            }

            // Find explicit types not generating a value
            foreach (var entityType in m_entityTypeLineInfos.Keys)
            {
                if (!reachableTypes.Contains(entityType))
                {
                    entityTypes.AddRange(entityType, m_entityTypeLineInfos.EnumerateValues(entityType));
                }
            }
        }
 private void CollectUnreachableTypes(
     Set <EntityType> reachableTypes,
     out KeyToListMap <EntityType, LineInfo> entityTypes,
     out KeyToListMap <EntityType, LineInfo> isTypeOfEntityTypes)
 {
     entityTypes         = new KeyToListMap <EntityType, LineInfo>((IEqualityComparer <EntityType>)EqualityComparer <EntityType> .Default);
     isTypeOfEntityTypes = new KeyToListMap <EntityType, LineInfo>((IEqualityComparer <EntityType>)EqualityComparer <EntityType> .Default);
     if (reachableTypes.Count == this.MappedEntityTypes.Count)
     {
         return;
     }
     foreach (EntityType key in this.m_isTypeOfLineInfos.Keys)
     {
         if (!MetadataHelper.GetTypeAndSubtypesOf((EdmType)key, this.m_itemCollection, false).Cast <EntityType>().Intersect <EntityType>((IEnumerable <EntityType>)reachableTypes).Any <EntityType>())
         {
             isTypeOfEntityTypes.AddRange(key, this.m_isTypeOfLineInfos.EnumerateValues(key));
         }
     }
     foreach (EntityType key in this.m_entityTypeLineInfos.Keys)
     {
         if (!reachableTypes.Contains(key))
         {
             entityTypes.AddRange(key, this.m_entityTypeLineInfos.EnumerateValues(key));
         }
     }
 }
示例#3
0
        private void InitializeFunctionMappingTranslators(
            EntitySetBase entitySetBase,
            EntityContainerMapping mapping)
        {
            KeyToListMap <AssociationSet, AssociationEndMember> keyToListMap = new KeyToListMap <AssociationSet, AssociationEndMember>((IEqualityComparer <AssociationSet>)EqualityComparer <AssociationSet> .Default);

            if (!this.m_functionMappingTranslators.ContainsKey(entitySetBase))
            {
                foreach (EntitySetMapping entitySetMap in mapping.EntitySetMaps)
                {
                    if (0 < entitySetMap.ModificationFunctionMappings.Count)
                    {
                        this.m_functionMappingTranslators.Add(entitySetMap.Set, ModificationFunctionMappingTranslator.CreateEntitySetTranslator(entitySetMap));
                        foreach (AssociationSetEnd associationSetEnd in entitySetMap.ImplicitlyMappedAssociationSetEnds)
                        {
                            AssociationSet parentAssociationSet = associationSetEnd.ParentAssociationSet;
                            if (!this.m_functionMappingTranslators.ContainsKey((EntitySetBase)parentAssociationSet))
                            {
                                this.m_functionMappingTranslators.Add((EntitySetBase)parentAssociationSet, ModificationFunctionMappingTranslator.CreateAssociationSetTranslator((AssociationSetMapping)null));
                            }
                            AssociationSetEnd oppositeEnd = MetadataHelper.GetOppositeEnd(associationSetEnd);
                            keyToListMap.Add(parentAssociationSet, oppositeEnd.CorrespondingAssociationEndMember);
                        }
                    }
                    else
                    {
                        this.m_functionMappingTranslators.Add(entitySetMap.Set, (ModificationFunctionMappingTranslator)null);
                    }
                }
                foreach (AssociationSetMapping relationshipSetMap in mapping.RelationshipSetMaps)
                {
                    if (relationshipSetMap.ModificationFunctionMapping != null)
                    {
                        AssociationSet set = (AssociationSet)relationshipSetMap.Set;
                        this.m_functionMappingTranslators.Add((EntitySetBase)set, ModificationFunctionMappingTranslator.CreateAssociationSetTranslator(relationshipSetMap));
                        keyToListMap.AddRange(set, Enumerable.Empty <AssociationEndMember>());
                    }
                    else if (!this.m_functionMappingTranslators.ContainsKey(relationshipSetMap.Set))
                    {
                        this.m_functionMappingTranslators.Add(relationshipSetMap.Set, (ModificationFunctionMappingTranslator)null);
                    }
                }
            }
            foreach (AssociationSet key in keyToListMap.Keys)
            {
                this.m_associationSetMetadata.Add(key, new AssociationSetMetadata(keyToListMap.EnumerateValues(key)));
            }
        }
        private void CollectUnreachableTypes(
            Set<EntityType> reachableTypes, out KeyToListMap<EntityType, LineInfo> entityTypes,
            out KeyToListMap<EntityType, LineInfo> isTypeOfEntityTypes)
        {
            // Collect line infos for types in violation
            entityTypes = new KeyToListMap<EntityType, LineInfo>(EqualityComparer<EntityType>.Default);
            isTypeOfEntityTypes = new KeyToListMap<EntityType, LineInfo>(EqualityComparer<EntityType>.Default);

            if (reachableTypes.Count
                == MappedEntityTypes.Count)
            {
                // All types are reachable; nothing to check
                return;
            }

            // Find IsTypeOf mappings where no type in hierarchy can generate a row
            foreach (var isTypeOf in m_isTypeOfLineInfos.Keys)
            {
                if (!MetadataHelper.GetTypeAndSubtypesOf(isTypeOf, m_itemCollection, false)
                                   .Cast<EntityType>()
                                   .Intersect(reachableTypes)
                                   .Any())
                {
                    // no type in the hierarchy is reachable...
                    isTypeOfEntityTypes.AddRange(isTypeOf, m_isTypeOfLineInfos.EnumerateValues(isTypeOf));
                }
            }

            // Find explicit types not generating a value
            foreach (var entityType in m_entityTypeLineInfos.Keys)
            {
                if (!reachableTypes.Contains(entityType))
                {
                    entityTypes.AddRange(entityType, m_entityTypeLineInfos.EnumerateValues(entityType));
                }
            }
        }
        // Loads and registers any function mapping translators for the given extent (and related container)
        private void InitializeFunctionMappingTranslators(EntitySetBase entitySetBase, EntityContainerMapping mapping)
        {
            var requiredEnds = new KeyToListMap <AssociationSet, AssociationEndMember>(
                EqualityComparer <AssociationSet> .Default);

            // see if function mapping metadata needs to be processed
            if (!m_functionMappingTranslators.ContainsKey(entitySetBase))
            {
                // load all function mapping data from the current entity container
                foreach (EntitySetMapping entitySetMapping in mapping.EntitySetMaps)
                {
                    if (0 < entitySetMapping.ModificationFunctionMappings.Count)
                    {
                        // register the function mapping
                        m_functionMappingTranslators.Add(
                            entitySetMapping.Set, ModificationFunctionMappingTranslator.CreateEntitySetTranslator(entitySetMapping));

                        // register "null" function translators for all implicitly mapped association sets
                        foreach (var end in entitySetMapping.ImplicitlyMappedAssociationSetEnds)
                        {
                            var associationSet = end.ParentAssociationSet;
                            if (!m_functionMappingTranslators.ContainsKey(associationSet))
                            {
                                m_functionMappingTranslators.Add(
                                    associationSet, ModificationFunctionMappingTranslator.CreateAssociationSetTranslator(null));
                            }

                            // Remember that the current entity set is required for all updates to the collocated
                            // relationship set. This entity set's end is opposite the target end for the mapping.
                            var oppositeEnd = MetadataHelper.GetOppositeEnd(end);
                            requiredEnds.Add(associationSet, oppositeEnd.CorrespondingAssociationEndMember);
                        }
                    }
                    else
                    {
                        // register null translator (so that we never attempt to process this extent again)
                        m_functionMappingTranslators.Add(entitySetMapping.Set, null);
                    }
                }

                foreach (AssociationSetMapping associationSetMapping in mapping.RelationshipSetMaps)
                {
                    if (null != associationSetMapping.ModificationFunctionMapping)
                    {
                        var set = (AssociationSet)associationSetMapping.Set;

                        // use indexer rather than Add since the association set may already have an implicit function
                        // mapping -- this explicit function mapping takes precedence in such cases
                        m_functionMappingTranslators.Add(
                            set,
                            ModificationFunctionMappingTranslator.CreateAssociationSetTranslator(associationSetMapping));

                        // remember that we've seen a function mapping for this association set, which overrides
                        // any other behaviors for determining required/optional ends
                        requiredEnds.AddRange(set, Enumerable.Empty <AssociationEndMember>());
                    }
                    else
                    {
                        if (!m_functionMappingTranslators.ContainsKey(associationSetMapping.Set))
                        {
                            // register null translator (so that we never attempt to process this extent again)
                            m_functionMappingTranslators.Add(associationSetMapping.Set, null);
                        }
                    }
                }
            }

            // register association metadata for all association sets encountered
            foreach (var associationSet in requiredEnds.Keys)
            {
                m_associationSetMetadata.Add(
                    associationSet, new AssociationSetMetadata(
                        requiredEnds.EnumerateValues(associationSet)));
            }
        }