private static bool CommonEntityTypeMappingRules(EntityTypeMapping etm, ref string errorMessage) { // 3. make sure that we don't have any C-side conditions foreach (var frag in etm.MappingFragments()) { foreach (var cond in frag.Conditions()) { if (cond.Name.RefName != null) { errorMessage = Resources.MappingDetails_ErrMslUnsupportedCondition; return(false); } } } // 4. make sure that function mappings are in their own ETM if (etm.ModificationFunctionMapping != null) { errorMessage = Resources.MappingDetails_ErrMslFunctionMappingsShouldBeSeparate; return(false); } // 7. ensure that ETMs only have one MappingFragment for a given table var mappedStorageEntitySets = new HashSet <EntitySet>(); foreach (var fragment in etm.MappingFragments()) { if (fragment.StoreEntitySet.Target != null) { if (mappedStorageEntitySets.Contains(fragment.StoreEntitySet.Target)) { errorMessage = Resources.MappingDetails_ErrMslTooManyFragments; return(false); } else { mappedStorageEntitySets.Add(fragment.StoreEntitySet.Target); } } } return(true); }
private static MappingFragment FindMappingFragment(EntityTypeMapping etm, EntityType table) { foreach (var fragment in etm.MappingFragments()) { if (fragment.StoreEntitySet.Target == table.EntitySet) { return(fragment); } } return(null); }
/// <summary> /// Creates a new EntityTypeMapping in the existing EntitySetMapping /// based on another EntityTypeMapping (etmToClone) in a different artifact. /// All the other parameters are presumed to already exist in the same artifact /// as the EntitySetMapping. /// </summary> internal static EntityTypeMapping CloneEntityTypeMapping( CommandProcessorContext cpc, EntityTypeMapping etmToClone, EntitySetMapping existingEntitySetMapping, ConceptualEntityType existingEntityType, EntityTypeMappingKind kind) { var createETM = new CreateEntityTypeMappingCommand(existingEntitySetMapping, existingEntityType, kind); var cp = new CommandProcessor(cpc, createETM); cp.Invoke(); var etm = createETM.EntityTypeMapping; foreach (var mappingFragment in etmToClone.MappingFragments()) { var sesToClone = mappingFragment.StoreEntitySet.Target as StorageEntitySet; var ses = existingEntitySetMapping.EntityContainerMapping.Artifact. StorageModel().FirstEntityContainer.GetFirstNamedChildByLocalName(sesToClone.LocalName.Value) as StorageEntitySet; CreateMappingFragmentCommand.CloneMappingFragment(cpc, mappingFragment, etm, ses); } return(etm); }
private static void GatherConditionsForEntityTypeMapping(EntityInfo info, EntityTypeMapping etm) { foreach (var frag in etm.MappingFragments()) { Debug.Assert(frag.StoreEntitySet.Target != null, "Found a MappingFragment with an unknown StoreEntitySet binding"); Debug.Assert( frag.StoreEntitySet.Target.EntityType.Target != null, "Found an S-Side entity set with an unknown entity binding"); if (frag.StoreEntitySet.Target != null && frag.StoreEntitySet.Target.EntityType.Target != null && info.HasTable(frag.StoreEntitySet.Target.EntityType.Target) == false) { var table = frag.StoreEntitySet.Target.EntityType.Target; var ti = new TableInfo(table); ti.EntityTypeMappingKind = etm.Kind; info.Tables.Add(table, ti); } foreach (var cond in frag.Conditions()) { info.Conditions.Add(cond); } } }
private static void GatherScalarsForEntityTypeMapping(EntityInfo info, EntityTypeMapping etm) { foreach (var frag in etm.MappingFragments()) { Debug.Assert(frag.StoreEntitySet.Target != null, "frag.StoreEntitySet.Target should not be null"); Debug.Assert( frag.StoreEntitySet.Target.EntityType.Target != null, "frag.StoreEntitySet.Target.EntityType.Target should not be null"); if (frag.StoreEntitySet.Target != null && frag.StoreEntitySet.Target.EntityType.Target != null && info.HasTable(frag.StoreEntitySet.Target.EntityType.Target) == false) { var table = frag.StoreEntitySet.Target.EntityType.Target; var ti = new TableInfo(table); ti.EntityTypeMappingKind = etm.Kind; info.Tables.Add(table, ti); } foreach (var sp in frag.ScalarProperties()) { if (info.KeyProperties.Contains(sp.Name.Target)) { info.KeyScalars.Add(sp); } else { info.NonKeyScalars.Add(sp); } } foreach (var cp in frag.ComplexProperties()) { GatherScalarsFromComplexProperty(info, cp); } } }