internal static XElement ConstructEntityContainerMapping(EdmItemCollection edm, string csdlNamespace) { var entityContainerMappingElement = new XElement( _msl + "EntityContainerMapping", new XAttribute("StorageEntityContainer", OutputGeneratorHelpers.ConstructStorageEntityContainerName(csdlNamespace)), new XAttribute("CdmEntityContainer", edm.GetEntityContainerName())); return(entityContainerMappingElement); }
internal static XElement ConstructEntityContainer( EdmItemCollection edm, string databaseSchemaName, string csdlNamespace, string ssdlNamespace) { var entityContainerElement = new XElement( _ssdl + "EntityContainer", new XAttribute("Name", OutputGeneratorHelpers.ConstructStorageEntityContainerName(csdlNamespace))); #region Constructing EntitySets // In TPT, we need to create the SSDL EntitySets from the EntityTypes; we create another table for the derived type. foreach (var entityType in edm.GetAllEntityTypes()) { var entitySetElement = ConstructEntitySet( ssdlNamespace, OutputGeneratorHelpers.GetStorageEntityTypeName(entityType, edm), OutputGeneratorHelpers.GetStorageEntityTypeName(entityType, edm), "Tables", databaseSchemaName); // we would also tack on DefiningQueries here if we wanted entityContainerElement.Add(entitySetElement); } // Find all *:* Associations and create EntitySets in the SSDL foreach (var associationSet in edm.GetAllAssociationSets().Where(set => set.GetAssociation().IsManyToMany())) { var entitySetElement = ConstructEntitySet( ssdlNamespace, associationSet.Name, associationSet.ElementType.Name, "Tables", databaseSchemaName); entityContainerElement.Add(entitySetElement); } #endregion #region Constructing AssociationSets foreach (var associationSet in edm.GetAllAssociationSets()) { var assoc = associationSet.GetAssociation(); if (assoc.GetEnd1() != null && assoc.GetEnd2() != null) { // *:* C-Space associations: we will have two S-space associations bound to the pair table corresponding to each end if (assoc.IsManyToMany()) { // create an association from the first end to the pair table var associationSet1Element = ConstructAssociationSet( ssdlNamespace, OutputGeneratorHelpers.GetStorageAssociationSetNameFromManyToMany(associationSet, assoc.GetEnd1()), OutputGeneratorHelpers.GetStorageAssociationNameFromManyToMany(assoc.GetEnd1()), assoc.GetEnd1().Name, OutputGeneratorHelpers.GetStorageEntityTypeName(assoc.GetEnd1().GetEntityType(), edm), assoc.Name, associationSet.Name); // create an association from the second end to the pair table var associationSet2Element = ConstructAssociationSet( ssdlNamespace, OutputGeneratorHelpers.GetStorageAssociationSetNameFromManyToMany(associationSet, assoc.GetEnd2()), OutputGeneratorHelpers.GetStorageAssociationNameFromManyToMany(assoc.GetEnd2()), assoc.GetEnd2().Name, OutputGeneratorHelpers.GetStorageEntityTypeName(assoc.GetEnd2().GetEntityType(), edm), assoc.Name, associationSet.Name); entityContainerElement.Add(associationSet1Element); entityContainerElement.Add(associationSet2Element); } // All other associations: we essentially mirror the C-space associations else { var associationSetElement = ConstructAssociationSet( ssdlNamespace, associationSet.Name, assoc.Name, assoc.GetEnd1().Name, OutputGeneratorHelpers.GetStorageEntityTypeName(assoc.GetEnd1().GetEntityType(), edm), assoc.GetEnd2().Name, OutputGeneratorHelpers.GetStorageEntityTypeName(assoc.GetEnd2().GetEntityType(), edm)); entityContainerElement.Add(associationSetElement); } } } // Now we will construct AssociationSets with PK:PK associations based off of inheritance foreach (var derivedType in edm.GetAllEntityTypes().Where(et => et.BaseType != null)) { entityContainerElement.Add( ConstructAssociationSet( ssdlNamespace, String.Format( CultureInfo.CurrentCulture, Resources.CodeViewFKConstraintDerivedType, derivedType.Name, derivedType.BaseType.Name), String.Format( CultureInfo.CurrentCulture, Resources.CodeViewFKConstraintDerivedType, derivedType.Name, derivedType.BaseType.Name), derivedType.BaseType.Name, OutputGeneratorHelpers.GetStorageEntityTypeName(derivedType.BaseType as EntityType, edm), derivedType.Name, OutputGeneratorHelpers.GetStorageEntityTypeName(derivedType, edm))); } #endregion var csdlEntityContainer = edm.GetItems <EntityContainer>().FirstOrDefault(); Debug.Assert(csdlEntityContainer != null, "Could not find the CSDL EntityContainer to migrate extended properties"); if (csdlEntityContainer != null) { OutputGeneratorHelpers.CopyExtendedPropertiesToSsdlElement(csdlEntityContainer, entityContainerElement); } return(entityContainerElement); }