示例#1
0
        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);
                    }
                }
            }
        }
        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);
                    }
                }
            }
        }
        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;
        }
        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;
        }
示例#5
0
        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);
            }
        }
示例#6
0
        internal static void ProcessStoredProcedureReturnTypeInformation(
            EFArtifact artifact,
            Dictionary <EntityStoreSchemaFilterEntry, IDataSchemaProcedure> newFunctionSchemaProceduresMap, IList <Command> commands,
            bool shouldCreateComposableFunctionImports)
        {
            if (null == artifact)
            {
                Debug.Fail("null artifact");
                return;
            }

            if (null == newFunctionSchemaProceduresMap)
            {
                Debug.Fail("Null newFunctionSchemaProceduresMap for artifact " + artifact.Uri);
                return;
            }

            var sem = artifact.StorageModel();

            if (null == sem)
            {
                Debug.Fail("Null StorageEntityModel for artifact " + artifact.Uri);
                return;
            }

            var storageEntityContainerName = sem.FirstEntityContainer.LocalName.Value;

            if (string.IsNullOrWhiteSpace(storageEntityContainerName))
            {
                Debug.Fail("Null or whitespace StorageEntityContainerName for artifact " + artifact.Uri);
                return;
            }

            foreach (var entry in newFunctionSchemaProceduresMap.Keys)
            {
                var     schemaProcedure = newFunctionSchemaProceduresMap[entry];
                Command cmd             = null;
                if (null == schemaProcedure)
                {
                    // schemaProcedure information was not collected - so delete the Function
                    var dbObj = DatabaseObject.CreateFromEntityStoreSchemaFilterEntry(entry, storageEntityContainerName);
                    var func  = ModelHelper.FindFunction(sem, dbObj);
                    Debug.Assert(func != null, "Could not find Function to delete matching Database Object " + dbObj.ToString());
                    if (null != func)
                    {
                        cmd = func.GetDeleteCommand();
                    }
                }
                else
                {
                    cmd = new CreateMatchingFunctionImportCommand(schemaProcedure, shouldCreateComposableFunctionImports);
                }

                if (null != cmd)
                {
                    commands.Add(cmd);
                }
            }
        }
 public void Invoke()
 {
     if (_artifact != null)
     {
         Initialize(_artifact.StorageModel());
         PropagateAllStoragePropertyFacets(_artifact);
     }
 }
        public static T GetStorageChildByName <T>(this EFArtifact artifact, string childName)
            where T : EFNameableItem
        {
            Debug.Assert(artifact != null, "artifact != null");

            var storageModel = artifact.StorageModel();

            return((T)storageModel.GetFirstNamedChildByLocalName(childName));
        }
        internal static string GetSsdlFromArtifact(EFArtifact artifact)
        {
            Debug.Assert(artifact != null, "Artifact is null ");
            if (artifact != null)
            {
                return(GetSchemaFromRuntimeModelRoot(artifact.StorageModel()));
            }

            return(String.Empty);
        }
示例#10
0
        private static void GetExistingTablesViewsAndSprocs(
            EFArtifact artifact,
            out SortedDictionary <DatabaseObject, int> existingTables,
            out SortedDictionary <DatabaseObject, int> existingViews,
            out SortedDictionary <DatabaseObject, int> existingStoredProcs)
        {
            existingTables      = new SortedDictionary <DatabaseObject, int>(_databaseObjectNameFirstComparer);
            existingViews       = new SortedDictionary <DatabaseObject, int>(_databaseObjectNameFirstComparer);
            existingStoredProcs = new SortedDictionary <DatabaseObject, int>(_databaseObjectNameFirstComparer);

            if (artifact != null &&
                artifact.StorageModel() != null)
            {
                if (artifact.StorageModel().EntityTypes() != null)
                {
                    foreach (var es in artifact.StorageModel().FirstEntityContainer.EntitySets())
                    {
                        var ses = es as StorageEntitySet;
                        if (null != ses)
                        {
                            var tableOrView = DatabaseObject.CreateFromEntitySet(ses);
                            if (ses.StoreSchemaGeneratorTypeIsView)
                            {
                                existingViews.Add(tableOrView, 0);
                            }
                            else
                            {
                                existingTables.Add(tableOrView, 0);
                            }
                        }
                    }
                }

                if (artifact.StorageModel().Functions() != null)
                {
                    foreach (var f in artifact.StorageModel().Functions())
                    {
                        var ssp = DatabaseObject.CreateFromFunction(f);
                        existingStoredProcs.Add(ssp, 0);
                    }
                }
            }
        }
示例#11
0
        public void Invoke()
        {
            if (_artifact == null &&
                _storageProperty == null)
            {
                Debug.Fail("both _artifact and _storageProperty are null");
                return;
            }
            else if (_artifact != null &&
                     _storageProperty != null)
            {
                Debug.Fail("both _artifact and _storageProperty are non-null");
                return;
            }

            if (_storageProperty != null)
            {
                // propagate SGP for just this StorageProperty
                PropagateConceptualSGPToStorageProperty(_storageProperty);
            }
            else
            {
                // propagate SGP for all StorageProperties in the artifact
                if (_artifact.StorageModel() != null)
                {
                    foreach (var et in _artifact.StorageModel().EntityTypes())
                    {
                        foreach (var prop in et.Properties())
                        {
                            var sProp = prop as StorageProperty;
                            Debug.Assert(
                                null != sProp,
                                "property of Storage Model EntityType has type " + prop.GetType().FullName + ", should be "
                                + typeof(StorageProperty).FullName);
                            if (null != sProp)
                            {
                                PropagateConceptualSGPToStorageProperty(sProp);
                            }
                        }
                    }
                }
            }
        }
        private void PropagateAllStoragePropertyFacets(EFArtifact artifact)
        {
            var sModel = artifact.StorageModel();

            if (null == sModel)
            {
                Debug.Fail("null StorageEntityModel");
                return;
            }

            var cModel = artifact.ConceptualModel();

            if (null == cModel)
            {
                Debug.Fail("null ConceptualEntityModel");
                return;
            }

            // loop over every S-side Property
            foreach (var sSideEntityType in sModel.EntityTypes())
            {
                foreach (var sSideProperty in sSideEntityType.Properties())
                {
                    // add every mapped C-side Property whose parent is a C-side EntityType (as opposed to a ComplexType)
                    var cSideProperties = new HashSet <Property>();
                    foreach (var scalarProp in sSideProperty.GetAntiDependenciesOfType <ScalarProperty>())
                    {
                        // only count mappings through EntitySetMapping and EntityTypeMapping (MappingFragment only
                        // appears as a child in these kinds of mappings). Mappings through e.g.
                        // AssociationSetMapping do not identify the C-side properties to be updated.
                        if (scalarProp.GetParentOfType(typeof(MappingFragment)) != null)
                        {
                            var cSideProperty = scalarProp.Name.Target;
                            if (null != cSideProperty &&
                                null != cSideProperty.GetParentOfType(typeof(EntityType)) &&
                                false == cSideProperties.Contains(cSideProperty))
                            {
                                cSideProperties.Add(cSideProperty);
                            }
                        }
                    }

                    // propagate the facets for this S-side Property to all the C-side Properties that are mapped to it
                    foreach (var mappedCSideProperty in cSideProperties)
                    {
                        // for each mapped C-side Property, loop over all the facet-synchronizers invoking them
                        foreach (var facetSynchronizer in _facetSynchronizers)
                        {
                            facetSynchronizer.Invoke(sSideProperty, mappedCSideProperty);
                        }
                    }
                }
            }
        }
示例#13
0
        private void FindNewStorageEntitySetsWithSameName(
            EFArtifact artifact, out HashSet <StorageEntitySet> storageEntitySetsWithSameNameButDifferentIdentity)
        {
            storageEntitySetsWithSameNameButDifferentIdentity = new HashSet <StorageEntitySet>();

            if (null != artifact &&
                null != artifact.StorageModel() &&
                null != artifact.StorageModel().FirstEntityContainer)
            {
                // set up Dictionary of EntitySetName to EntitySet for new (DB-based) artifact
                var newEntitySetMap = new Dictionary <string, EntitySet>();
                foreach (var newEntitySet in artifact.StorageModel().FirstEntityContainer.EntitySets())
                {
                    newEntitySetMap.Add(newEntitySet.LocalName.Value, newEntitySet);
                }

                // now compare all names - if we find a local name match compare identities
                // if they have the same name but different identities then add to returned HashSet
                foreach (var existingEntitySet in _preExistingModel.AllTablesAndViewsDictionary)
                {
                    var existingEntitySetLocalName = existingEntitySet.Value;

                    EntitySet newEntitySet;
                    if (newEntitySetMap.TryGetValue(existingEntitySetLocalName, out newEntitySet))
                    {
                        var newStorageEntitySet = newEntitySet as StorageEntitySet;
                        if (null != newStorageEntitySet)
                        {
                            // we have a StorageEntitySet in the DB-based artifact which is the
                            // same as one in the pre-existing artifact. Now compare identities.
                            var newEntitySetIdentity      = DatabaseObject.CreateFromEntitySet(newStorageEntitySet);
                            var existingEntitySetIdentity = existingEntitySet.Key;
                            if (!newEntitySetIdentity.Equals(existingEntitySetIdentity))
                            {
                                storageEntitySetsWithSameNameButDifferentIdentity.Add(newStorageEntitySet);
                            }
                        }
                    }
                }
            }
        }
        private void FindNewStorageEntitySetsWithSameName(
            EFArtifact artifact, out HashSet<StorageEntitySet> storageEntitySetsWithSameNameButDifferentIdentity)
        {
            storageEntitySetsWithSameNameButDifferentIdentity = new HashSet<StorageEntitySet>();

            if (null != artifact
                && null != artifact.StorageModel()
                && null != artifact.StorageModel().FirstEntityContainer)
            {
                // set up Dictionary of EntitySetName to EntitySet for new (DB-based) artifact
                var newEntitySetMap = new Dictionary<string, EntitySet>();
                foreach (var newEntitySet in artifact.StorageModel().FirstEntityContainer.EntitySets())
                {
                    newEntitySetMap.Add(newEntitySet.LocalName.Value, newEntitySet);
                }

                // now compare all names - if we find a local name match compare identities
                // if they have the same name but different identities then add to returned HashSet
                foreach (var existingEntitySet in _preExistingModel.AllTablesAndViewsDictionary)
                {
                    var existingEntitySetLocalName = existingEntitySet.Value;

                    EntitySet newEntitySet;
                    if (newEntitySetMap.TryGetValue(existingEntitySetLocalName, out newEntitySet))
                    {
                        var newStorageEntitySet = newEntitySet as StorageEntitySet;
                        if (null != newStorageEntitySet)
                        {
                            // we have a StorageEntitySet in the DB-based artifact which is the
                            // same as one in the pre-existing artifact. Now compare identities.
                            var newEntitySetIdentity = DatabaseObject.CreateFromEntitySet(newStorageEntitySet);
                            var existingEntitySetIdentity = existingEntitySet.Key;
                            if (!newEntitySetIdentity.Equals(existingEntitySetIdentity))
                            {
                                storageEntitySetsWithSameNameButDifferentIdentity.Add(newStorageEntitySet);
                            }
                        }
                    }
                }
            }
        }
示例#15
0
        private void FindNewStorageFunctionsWithSameName(
            EFArtifact artifact, out HashSet <Function> storageFunctionsWithSameNameButDifferentIdentity)
        {
            storageFunctionsWithSameNameButDifferentIdentity = new HashSet <Function>();

            if (null != artifact &&
                null != artifact.StorageModel())
            {
                // set up Dictionary of EntitySetName to EntitySet for new (DB-based) artifact
                var newFunctionMap = new Dictionary <string, Function>();
                foreach (var newFunction in artifact.StorageModel().Functions())
                {
                    newFunctionMap.Add(newFunction.LocalName.Value, newFunction);
                }

                // now compare all names - if we find a local name match compare identities
                // if they have the same name but different identities then add to returned HashSet
                foreach (var existingFunction in _preExistingModel.AllFunctionsDictionary)
                {
                    var existingFunctionLocalName = existingFunction.Value;

                    Function newFunction;
                    if (newFunctionMap.TryGetValue(existingFunctionLocalName, out newFunction))
                    {
                        if (null != newFunction)
                        {
                            // we have a Function in the DB-based artifact which is the
                            // same as one in the pre-existing artifact. Now compare identities.
                            var newFunctionIdentity      = DatabaseObject.CreateFromFunction(newFunction);
                            var existingFunctionIdentity = existingFunction.Key;
                            if (!newFunctionIdentity.Equals(existingFunctionIdentity))
                            {
                                storageFunctionsWithSameNameButDifferentIdentity.Add(newFunction);
                            }
                        }
                    }
                }
            }
        }
示例#16
0
        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);
                        }
                    }
                }
            }
        }
        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);
                        }
                    }
                }
            }
        }
        internal static string GetProviderManifestTokenDisconnected(EFArtifact artifact)
        {
            var storageModel = artifact.StorageModel();

            if (storageModel != null &&
                storageModel.ProviderManifestToken != null)
            {
                return(storageModel.ProviderManifestToken.Value);
            }

            Debug.Fail("Unable to determine the provider manifest token for the SSDL");

            return(String.Empty);
        }
示例#19
0
        private static string GetParameterType(IRawDataSchemaParameter parameter, EFArtifact artifact)
        {
            var type = ModelHelper.GetPrimitiveType(artifact.StorageModel(), parameter.NativeDataType, parameter.ProviderDataType);

            if (type != null)
            {
                return(type.Name);
            }

            Debug.Fail(
                "Unable to find EDM primitive type for DB type:" + parameter.NativeDataType + ", provider data type:"
                + parameter.ProviderDataType);

            return(null);
        }
        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;
        }
        internal static bool IsStorageModelEmpty(EFArtifact artifact)
        {
            var result = false;

            var storageModel = artifact.StorageModel();
            if (storageModel != null)
            {
                var container = storageModel.FirstEntityContainer as StorageEntityContainer;
                if (container != null)
                {
                    var element = container.Children.OfType<EFElement>().FirstOrDefault<EFElement>();
                    if (element == null)
                    {
                        result = true;
                    }
                }
            }

            return result;
        }
示例#22
0
        internal static bool IsStorageModelEmpty(EFArtifact artifact)
        {
            var result = false;

            var storageModel = artifact.StorageModel();

            if (storageModel != null)
            {
                var container = storageModel.FirstEntityContainer as StorageEntityContainer;
                if (container != null)
                {
                    var element = container.Children.OfType <EFElement>().FirstOrDefault <EFElement>();
                    if (element == null)
                    {
                        result = true;
                    }
                }
            }

            return(result);
        }
            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
                );
        }
        protected override void InvokeInternal(CommandProcessorContext cpc)
        {
            var service  = cpc.EditingContext.GetEFArtifactService();
            var artifact = service.Artifact;

            Debug.Assert(artifact != null, "Null Artifact");
            if (null == artifact)
            {
                return;
            }

            // construct a mapping of the existing model's C-side objects
            // and their S-side identities before anything is updated
            var existingModel = new ExistingModelSummary(artifact);

            // replace the old SSDL with the new and fixup any references
            // in the MSL that broke because of the replacement of the SSDL
            // (i.e. the S-side Alias and S-side EntityContainer name)
            var replaceSsdlCommand = new ReplaceSsdlCommand(_newArtifactFromDB.StorageModel());

            CommandProcessor.InvokeSingleCommand(cpc, replaceSsdlCommand);

            // remove any mappings with references which no longer work
            // with the new SSDL
            var deleteUnboundMappingsCommand = new DeleteUnboundMappingsCommand();

            CommandProcessor.InvokeSingleCommand(cpc, deleteUnboundMappingsCommand);

            // remove any mappings which should no longer be mapped with the new SSDL
            // but actually are because a new S-side object with identical name
            // but different identity has been added
            var deleteChangedIdentityMappingsCommand = new DeleteChangedIdentityMappingsCommand(existingModel);

            CommandProcessor.InvokeSingleCommand(cpc, deleteChangedIdentityMappingsCommand);

            // from the temp model for the updated database determine which
            // C-side objects need to be added/updated and then update the
            // C- and M- side models appropriately
            var modelFromUpdatedDatabase = new UpdatedModelSummary(_newArtifactFromDB);
            var updateCsdlAndMslCommand  =
                new UpdateConceptualAndMappingModelsCommand(existingModel, modelFromUpdatedDatabase);

            CommandProcessor.InvokeSingleCommand(cpc, updateCsdlAndMslCommand);

            // fix up Function Import parameters and add integrity checks
            if (artifact.MappingModel() != null &&
                artifact.MappingModel().FirstEntityContainerMapping != null)
            {
                // Function Import parameters are now out-of-date compared to the updated Function ones.
                // We need to update them as otherwise there is no way to do so using Escher.
                foreach (var fim in artifact.MappingModel().FirstEntityContainerMapping.FunctionImportMappings())
                {
                    if (null != fim.FunctionImportName &&
                        null != fim.FunctionImportName.Target &&
                        null != fim.FunctionName &&
                        null != fim.FunctionName.Target)
                    {
                        CreateFunctionImportCommand.UpdateFunctionImportParameters(
                            cpc, fim.FunctionImportName.Target, fim.FunctionName.Target);
                    }
                }

                // Add integrity checks to enforce mapping rules
                foreach (var esm in artifact.MappingModel().FirstEntityContainerMapping.EntitySetMappings())
                {
                    EnforceEntitySetMappingRules.AddRule(cpc, esm);
                }

                // add the integrity check to propagate all appropriate StoreGeneratedPattern values to the S-side
                // Note: should not propagate "None"/defaulted values to prevent those C-side values overwriting
                // correctly updated S-side StoreGeneratedPattern values which were just received from the runtime
                PropagateStoreGeneratedPatternToStorageModel.AddRule(cpc, artifact, false);

                // Add integrity check to enforce synchronizing C-side Property facets to S-side values
                var shouldSynchronizePropertyFacets = ModelHelper.GetDesignerPropertyValueFromArtifactAsBool(
                    OptionsDesignerInfo.ElementName,
                    OptionsDesignerInfo.AttributeSynchronizePropertyFacets, OptionsDesignerInfo.SynchronizePropertyFacetsDefault(artifact),
                    artifact);
                if (shouldSynchronizePropertyFacets)
                {
                    PropagateStoragePropertyFacetsToConceptualModel.AddRule(cpc, artifact);
                }
            }
        }
        private static string GetParameterType(IRawDataSchemaParameter parameter, EFArtifact artifact)
        {
            var type = ModelHelper.GetPrimitiveType(artifact.StorageModel(), parameter.NativeDataType, parameter.ProviderDataType);
            if (type != null)
            {
                return type.Name;
            }

            Debug.Fail(
                "Unable to find EDM primitive type for DB type:" + parameter.NativeDataType + ", provider data type:"
                + parameter.ProviderDataType);

            return null;
        }
        private void FindNewStorageFunctionsWithSameName(
            EFArtifact artifact, out HashSet<Function> storageFunctionsWithSameNameButDifferentIdentity)
        {
            storageFunctionsWithSameNameButDifferentIdentity = new HashSet<Function>();

            if (null != artifact
                && null != artifact.StorageModel())
            {
                // set up Dictionary of EntitySetName to EntitySet for new (DB-based) artifact
                var newFunctionMap = new Dictionary<string, Function>();
                foreach (var newFunction in artifact.StorageModel().Functions())
                {
                    newFunctionMap.Add(newFunction.LocalName.Value, newFunction);
                }

                // now compare all names - if we find a local name match compare identities
                // if they have the same name but different identities then add to returned HashSet
                foreach (var existingFunction in _preExistingModel.AllFunctionsDictionary)
                {
                    var existingFunctionLocalName = existingFunction.Value;

                    Function newFunction;
                    if (newFunctionMap.TryGetValue(existingFunctionLocalName, out newFunction))
                    {
                        if (null != newFunction)
                        {
                            // we have a Function in the DB-based artifact which is the
                            // same as one in the pre-existing artifact. Now compare identities.
                            var newFunctionIdentity = DatabaseObject.CreateFromFunction(newFunction);
                            var existingFunctionIdentity = existingFunction.Key;
                            if (!newFunctionIdentity.Equals(existingFunctionIdentity))
                            {
                                storageFunctionsWithSameNameButDifferentIdentity.Add(newFunction);
                            }
                        }
                    }
                }
            }
        }