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))); } }
// 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))); } }