internal UpdatedModelSummary(EFArtifact artifact) { _artifact = artifact; Debug.Assert(artifact != null, "Null artifact"); if (artifact != null) { if (null != artifact.MappingModel() && null != artifact.MappingModel().FirstEntityContainerMapping) { RecordEntityTypeIdentities( artifact.MappingModel().FirstEntityContainerMapping); // build the association summary _associationSummary = AssociationSummary.ConstructAssociationSummary(artifact); } if (null != artifact.StorageModel() && null != artifact.StorageModel().FirstEntityContainer) { var sec = artifact.StorageModel().FirstEntityContainer as StorageEntityContainer; if (sec != null) { RecordStorageProperties(sec); } } } }
private static void ReplaceMappingContainerRef(EFArtifact existingArtifact, string oldStorageEntityContainerName) { Debug.Assert(existingArtifact != null, "ReplaceMappingContainerRef(): received null existingArtifact"); if (!string.IsNullOrEmpty(oldStorageEntityContainerName) && existingArtifact.StorageModel() != null && existingArtifact.StorageModel().FirstEntityContainer != null && existingArtifact.MappingModel() != null && existingArtifact.MappingModel().FirstEntityContainerMapping != null && existingArtifact.MappingModel().FirstEntityContainerMapping.StorageEntityContainer != null && existingArtifact.MappingModel().FirstEntityContainerMapping.StorageEntityContainer.RefName == oldStorageEntityContainerName) { existingArtifact.MappingModel().FirstEntityContainerMapping.StorageEntityContainer. SetRefName(existingArtifact.StorageModel().FirstEntityContainer); } }
protected override void InvokeInternal(CommandProcessorContext cpc) { if (_artifact == null) { throw new InvalidOperationException("InvokeInternal is called when _artifact is null"); } var ecm = new EntityContainerMapping(_artifact.MappingModel(), null); ecm.CdmEntityContainer.SetRefName(_artifact.ConceptualModel().FirstEntityContainer); ecm.StorageEntityContainer.SetRefName(_artifact.StorageModel().FirstEntityContainer); _artifact.MappingModel().AddEntityContainerMapping(ecm); XmlModelHelper.NormalizeAndResolve(ecm); _created = ecm; }
private static void UpdateMappingModel(EFArtifact existingArtifact, string oldStorageEntityContainerName) { // replaces the possible reference to the old S-side EntityContainer name ReplaceMappingContainerRef(existingArtifact, oldStorageEntityContainerName); // normalize and resolve the changes we just made above XmlModelHelper.NormalizeAndResolve(existingArtifact.MappingModel()); }
internal static string GetMslFromArtifact(EFArtifact artifact) { Debug.Assert(artifact != null, "Artifact is null "); if (artifact != null) { return(GetSchemaFromRuntimeModelRoot(artifact.MappingModel())); } return(String.Empty); }
public static EntitySetMapping GetFreshEntitySetMapping(this EFArtifact artifact, string entitySetName) { Debug.Assert(artifact != null, "artifact != null"); Debug.Assert(!string.IsNullOrWhiteSpace(entitySetName), "!string.IsNullOrWhiteSpace(entitySetName)"); return (artifact.MappingModel() .EntityContainerMappings().Single() .EntitySetMappings().SingleOrDefault(m => m.Name.RefName == entitySetName)); }
public static AssociationSetMapping GetFreshAssociationSetMapping(this EFArtifact artifact, string associationSetMappingName) { Debug.Assert(artifact != null, "artifact != null"); Debug.Assert(!string.IsNullOrWhiteSpace(associationSetMappingName), "!string.IsNullOrWhiteSpace(associationSetName)"); return(artifact .MappingModel() .EntityContainerMappings().Single() .AssociationSetMappings().SingleOrDefault(asm => asm.Name.Target.LocalName.Value == associationSetMappingName)); }
public static FunctionImportMapping GetFreshFunctionMapping(this EFArtifact artifact, string functionImportName) { Debug.Assert(artifact != null, "artifact != null"); Debug.Assert(!string.IsNullOrWhiteSpace(functionImportName), "!string.IsNullOrWhiteSpace(functionImportName)"); return (artifact.MappingModel() .EntityContainerMappings().Single() .FunctionImportMappings().SingleOrDefault(m => m.FunctionImportName.RefName == functionImportName)); }
internal static AssociationSummary ConstructAssociationSummary(EFArtifact artifact) { var ecm = artifact.MappingModel().FirstEntityContainerMapping; var summary = new AssociationSummary(); if (!EdmFeatureManager.GetForeignKeysInModelFeatureState(artifact.SchemaVersion).IsEnabled()) { if (ecm != null) { // Foreign keys in the model are not supported for this EDMX version. foreach (var asm in ecm.AssociationSetMappings()) { var cSideAssociation = asm.TypeName.Target; if (null != cSideAssociation) { var assocId = AssociationIdentityForAssociationSetMapping.CreateAssociationIdentity(asm); if (null != assocId) { summary.Add(cSideAssociation, assocId); } } } } } else { // Foreign keys in the model are supported for this EDMX version. foreach (var a in artifact.ConceptualModel().Associations()) { AssociationIdentity assocId = null; if (a.IsManyToMany == false && a.ReferentialConstraint != null) { assocId = AssociationIdentityForReferentialConstraint.CreateAssociationIdentity(a.ReferentialConstraint); } else { var asm = ModelHelper.FindAssociationSetMappingForConceptualAssociation(a); if (asm != null) { assocId = AssociationIdentityForAssociationSetMapping.CreateAssociationIdentity(asm); } } if (null != assocId) { summary.Add(a, assocId); } } } return(summary); }
internal ExistingModelSummary(EFArtifact artifact) { _artifact = artifact; if (null == artifact) { Debug.Fail("Null artifact"); } else { if (null != artifact.MappingModel() && null != artifact.MappingModel().FirstEntityContainerMapping) { RecordEntityTypeIdentities( artifact.MappingModel().FirstEntityContainerMapping); // build the association summary. _associationSummary = AssociationSummary.ConstructAssociationSummary(artifact); } if (null != artifact.ConceptualModel()) { RecordInheritanceAndEntityTypeMappings(artifact.ConceptualModel()); } if (null != artifact.StorageModel()) { RecordFunctions(artifact.StorageModel()); if (null != artifact.StorageModel().FirstEntityContainer) { var sec = artifact.StorageModel().FirstEntityContainer as StorageEntityContainer; if (sec != null) { RecordStorageEntitySetsAndProperties(sec); } } } } }
public static Condition GetFreshCondition(this EFArtifact artifact, string entitySetName, string columnName) { Debug.Assert(artifact != null, "artifact != null"); Debug.Assert(!string.IsNullOrWhiteSpace(entitySetName), "!string.IsNullOrWhiteSpace(entitySetName)"); Debug.Assert(!string.IsNullOrWhiteSpace(columnName), "!string.IsNullOrWhiteSpace(columnName)"); return(artifact.MappingModel() .EntityContainerMappings() .Single() .EntitySetMappings().Single(m => m.Name.RefName == entitySetName) .EntityTypeMappings().SelectMany(t => t.MappingFragments()) .SelectMany(f => f.Conditions()).SingleOrDefault(c => c.ColumnName.RefName == columnName)); }
internal CreateEntityContainerMappingCommand(EFArtifact artifact) { Debug.Assert(artifact != null, "artifact should not be null"); Debug.Assert( artifact.ConceptualModel().EntityContainerCount == 1, "conceptual model EntityContainer count (" + artifact.ConceptualModel().EntityContainerCount + ") should be 1"); Debug.Assert( artifact.StorageModel().EntityContainerCount == 1, "storage model EntityContainer count (" + artifact.StorageModel().EntityContainerCount + ") should be 1"); Debug.Assert( artifact.MappingModel().FirstEntityContainerMapping == null, "mapping model FirstEntityContainer should not be null"); _artifact = artifact; }
AddAssociationSetMappingForConceptualAssociation( CommandProcessorContext cpc, EFArtifact existingArtifact, Association assocInTempArtifact, Association assocInExistingArtifact, Dictionary<EntityType, EntityType> tempArtifactCEntityTypeToNewCEntityTypeInExistingArtifact) { // first find the AssociationSetMapping in the tempArtifact for this association var asmInTempArtifact = ModelHelper.FindAssociationSetMappingForConceptualAssociation(assocInTempArtifact); if (asmInTempArtifact == null) { if (!EdmFeatureManager.GetForeignKeysInModelFeatureState(existingArtifact.SchemaVersion).IsEnabled() || assocInTempArtifact.IsManyToMany) { // this is an error condition - we should have an association set mapping in this case, so assert and throw an exception throw new UpdateModelFromDatabaseException( string.Format( CultureInfo.CurrentCulture, Resources.UpdateFromDatabaseAssociationSetMappingCannotFind, assocInTempArtifact.ToPrettyString())); } else { // we don't expect an association set mapping here return; } } // next find the S-side EntitySet in the tempArtifact for this AssociationSetMapping var storeEntitySetInTempArtifact = asmInTempArtifact.StoreEntitySet.Target; if (storeEntitySetInTempArtifact == null) { throw new UpdateModelFromDatabaseException( string.Format( CultureInfo.CurrentCulture, Resources.UpdateFromDatabaseAssociationSetMappingCannotFindTempSSideEntitySet, asmInTempArtifact.ToPrettyString())); } // now find the S-side EntitySet in the existingArtifact which matches this // Note: LocalName's will be the same as the SSDL has been replaced StorageEntitySet storeEntitySetInExistingArtifact = null; foreach (var es in existingArtifact.StorageModel().FirstEntityContainer.EntitySets()) { if (es.LocalName.Value == storeEntitySetInTempArtifact.LocalName.Value) { storeEntitySetInExistingArtifact = es as StorageEntitySet; break; } } if (storeEntitySetInExistingArtifact == null) { throw new UpdateModelFromDatabaseException( string.Format( CultureInfo.CurrentCulture, Resources.UpdateFromDatabaseAssociationSetMappingCannotFindMatchingSSideEntitySet, storeEntitySetInTempArtifact.LocalName.Value)); } // now create a new AssociationSetMapping in the existingArtifact using the data // accumulated above CloneAssociationSetMapping( cpc, asmInTempArtifact, existingArtifact.MappingModel().FirstEntityContainerMapping, assocInExistingArtifact.AssociationSet, assocInExistingArtifact, storeEntitySetInExistingArtifact, tempArtifactCEntityTypeToNewCEntityTypeInExistingArtifact ); }
internal static FunctionImport CreateFunctionImport( EditingContext editingContext, EFArtifact artifact, Function selectedSproc, StorageEntityModel sModel, ConceptualEntityModel cModel, ConceptualEntityContainer cContainer, EntityType entityType, string originatingId) { FunctionImport functionImportResult = null; Debug.Assert(editingContext != null, "editingContext should not be null"); Debug.Assert(artifact != null, "artifact should not be null"); Debug.Assert(!string.IsNullOrEmpty(originatingId), "originatingId should not be null or empty"); // show dialog appropriate to framework version var result = ShowNewFunctionImportDialog( selectedSproc, null /* selectedSprocName Parameter */, sModel, cModel, cContainer, DialogsResource.NewFunctionImportDialog_AddFunctionImportTitle, entityType); // if user selected OK on the dialog then create the FunctionImport if (DialogResult.OK == result.DialogResult) { var commands = new Collection <Command>(); CreateComplexTypeCommand createComplexTypeCommand = null; // Make the decision based on what is returned by the dialog. // If return type is a string and result schema is not null, that means the user would like create a new complex type for the function import return. if (result.ReturnType is string && result.Schema != null) { createComplexTypeCommand = CreateMatchingFunctionImportCommand.AddCreateComplexTypeCommands( sModel, result.ReturnType as string, result.Schema.RawColumns, commands); } // If ReturnType is a complex type and result schema is not null, the complex type needs to be updated to be in sync with schema columns. else if (result.ReturnType is ComplexType && result.Schema != null) { var complexType = result.ReturnType as ComplexType; var propertiesDictionary = complexType.Properties().ToDictionary(p => p.LocalName.Value); CreateMatchingFunctionImportCommand.AddChangeComplexTypePropertiesCommands( complexType, propertiesDictionary, result.Schema.RawColumns, commands); } CreateFunctionImportCommand cmdFuncImp; if (createComplexTypeCommand == null) { cmdFuncImp = new CreateFunctionImportCommand(cContainer, result.Function, result.FunctionName, result.ReturnType); } else { // Pass in the pre-req command to create complex type to the command. cmdFuncImp = new CreateFunctionImportCommand(cContainer, result.Function, result.FunctionName, createComplexTypeCommand); } commands.Add(cmdFuncImp); // now add a FunctionImport and a FunctionImportMapping (if appropriate) if (artifact.MappingModel() != null && artifact.MappingModel().FirstEntityContainerMapping != null) { var cmdFuncImpMapping = new CreateFunctionImportMappingCommand( artifact.MappingModel().FirstEntityContainerMapping, result.Function, cmdFuncImp.Id); cmdFuncImpMapping.AddPreReqCommand(cmdFuncImp); commands.Add(cmdFuncImpMapping); IDictionary <string, string> mapPropertyNameToColumnName = null; if (result.Schema != null) { mapPropertyNameToColumnName = ModelHelper.ConstructComplexTypePropertyNameToColumnNameMapping( result.Schema.Columns.Select(c => c.Name).ToList()); } // Create explicit function-import result type mapping if the return type is a complex type. if (createComplexTypeCommand != null) { commands.Add( new CreateFunctionImportTypeMappingCommand(cmdFuncImpMapping, createComplexTypeCommand) { CreateDefaultScalarProperties = true, PropertyNameToColumnNameMap = mapPropertyNameToColumnName }); } else if (result.ReturnType is ComplexType) { commands.Add( new CreateFunctionImportTypeMappingCommand(cmdFuncImpMapping, result.ReturnType as ComplexType) { CreateDefaultScalarProperties = true, PropertyNameToColumnNameMap = mapPropertyNameToColumnName }); } } var cp = new CommandProcessor(editingContext, originatingId, Resources.Tx_CreateFunctionImport, commands); cp.Invoke(); functionImportResult = cmdFuncImp.FunctionImport; NavigateToFunction(functionImportResult); } return(functionImportResult); }
internal static AssociationSummary ConstructAssociationSummary(EFArtifact artifact) { var ecm = artifact.MappingModel().FirstEntityContainerMapping; var summary = new AssociationSummary(); if (!EdmFeatureManager.GetForeignKeysInModelFeatureState(artifact.SchemaVersion).IsEnabled()) { if (ecm != null) { // Foreign keys in the model are not supported for this EDMX version. foreach (var asm in ecm.AssociationSetMappings()) { var cSideAssociation = asm.TypeName.Target; if (null != cSideAssociation) { var assocId = AssociationIdentityForAssociationSetMapping.CreateAssociationIdentity(asm); if (null != assocId) { summary.Add(cSideAssociation, assocId); } } } } } else { // Foreign keys in the model are supported for this EDMX version. foreach (var a in artifact.ConceptualModel().Associations()) { AssociationIdentity assocId = null; if (a.IsManyToMany == false && a.ReferentialConstraint != null) { assocId = AssociationIdentityForReferentialConstraint.CreateAssociationIdentity(a.ReferentialConstraint); } else { var asm = ModelHelper.FindAssociationSetMappingForConceptualAssociation(a); if (asm != null) { assocId = AssociationIdentityForAssociationSetMapping.CreateAssociationIdentity(asm); } } if (null != assocId) { summary.Add(a, assocId); } } } return summary; }