src/Misc/EFTools/EntityDesignModel/Commands/ReplaceSsdlCommand.cs
/// <summary>
///     Compares the two Dictionaries passed in and constructs a Dictionary mapping
///     any old DatabaseObjects which exist in both artifacts but whose name has changed
///     in the new artifact. It then iterates over that Dictionary finding
///     anti-dependencies of each S-side object and updating those references to target
///     the updated name of the DatabaseObject in the new artifact.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="existingArtifactSSideMappings">Dictionary mapping S-side database objects to their names in the existing artifact</param>
/// <param name="newArtifactSSideMappings">Dictionary mapping S-side database objects to their names in the new artifact</param>
Compares the two Dictionaries passed in and constructs a Dictionary mapping
any old DatabaseObjects which exist in both artifacts but whose name has changed
in the new artifact. It then iterates over that Dictionary finding
anti-dependencies of each S-side object and updating those references to target
the updated name of the DatabaseObject in the new artifact.
Compares the two Dictionaries passed in and constructs a Dictionary mapping any old DatabaseObjects which exist in both artifacts but whose name has changed in the new artifact . It then iterates over that Dictionary finding anti - dependencies of each S - side object and updating those references to target the updated name of the DatabaseObject in the new artifact .
private static void UpdateOldDatabaseObjectReferencesToNewNames<T>(
            Dictionary<DatabaseObject, T> existingArtifactSSideMappings,
            Dictionary<DatabaseObject, T> newArtifactSSideMappings) where T : EFNameableItem
        {
            var existingDatabaseObjectToNewNameMappings = new Dictionary<T, string>();
            foreach (var databaseIdNamePair in existingArtifactSSideMappings)
            {
                var dbIdentity = databaseIdNamePair.Key;
                if (null != databaseIdNamePair.Value
                    && null != databaseIdNamePair.Value.LocalName
                    && !string.IsNullOrEmpty(databaseIdNamePair.Value.LocalName.Value))
                {
                    var oldName = databaseIdNamePair.Value.LocalName.Value;
                    T matchingNewDatabaseObject;
                    var newArtifactContainsDBIdentity =
                        newArtifactSSideMappings.TryGetValue(dbIdentity, out matchingNewDatabaseObject);
                    if (newArtifactContainsDBIdentity
                        && null != matchingNewDatabaseObject
                        && null != matchingNewDatabaseObject.LocalName
                        && !string.IsNullOrEmpty(matchingNewDatabaseObject.LocalName.Value)
                        && matchingNewDatabaseObject.LocalName.Value != oldName)
                    {
                        existingDatabaseObjectToNewNameMappings.Add(databaseIdNamePair.Value, matchingNewDatabaseObject.LocalName.Value);
                    }
                }
            }
            foreach (var existingDatabaseObjectNewNamePair in existingDatabaseObjectToNewNameMappings)
            {
                var existingDatabaseObject = existingDatabaseObjectNewNamePair.Key;
                var newName = existingDatabaseObjectNewNamePair.Value;
                var antiDepsArray = existingDatabaseObject.GetAntiDependencies().ToArray();
                foreach (var antiDep in antiDepsArray)
                {
                    var antiDepAsItemBinding = antiDep as ItemBinding;
                    if (null != antiDepAsItemBinding
                        && null != existingDatabaseObject.LocalName
                        && !string.IsNullOrEmpty(existingDatabaseObject.LocalName.Value))
                    {
                        antiDepAsItemBinding.UpdateRefNameNamePart(existingDatabaseObject.LocalName.Value, newName);
                    }
                }
            }
        }
private static void UpdateOldDatabaseObjectReferencesToNewNames < T > ( Dictionary < DatabaseObject , T > existingArtifactSSideMappings , Dictionary < DatabaseObject , T > newArtifactSSideMappings ) where T : EFNameableItem { var existingDatabaseObjectToNewNameMappings = new Dictionary < T , string > ( ) ; foreach ( var databaseIdNamePair in existingArtifactSSideMappings ) { var dbIdentity = databaseIdNamePair . Key ; if ( null != databaseIdNamePair . Value && null != databaseIdNamePair . Value . LocalName && ! string . IsNullOrEmpty ( databaseIdNamePair . Value . LocalName . Value ) ) { var oldName = databaseIdNamePair . Value . LocalName . Value ; T matchingNewDatabaseObject ; var newArtifactContainsDBIdentity = newArtifactSSideMappings . TryGetValue ( dbIdentity , out matchingNewDatabaseObject ) ; if ( newArtifactContainsDBIdentity && null != matchingNewDatabaseObject && null != matchingNewDatabaseObject . LocalName && ! string . IsNullOrEmpty ( matchingNewDatabaseObject . LocalName . Value ) && matchingNewDatabaseObject . LocalName . Value != oldName ) { existingDatabaseObjectToNewNameMappings . Add ( databaseIdNamePair . Value , matchingNewDatabaseObject . LocalName . Value ) ; } } } foreach ( var existingDatabaseObjectNewNamePair in existingDatabaseObjectToNewNameMappings ) { var existingDatabaseObject = existingDatabaseObjectNewNamePair . Key ; var newName = existingDatabaseObjectNewNamePair . Value ; var antiDepsArray = existingDatabaseObject . GetAntiDependencies ( ) . ToArray ( ) ; foreach ( var antiDep in antiDepsArray ) { var antiDepAsItemBinding = antiDep as ItemBinding ; if ( null != antiDepAsItemBinding && null != existingDatabaseObject . LocalName && ! string . IsNullOrEmpty ( existingDatabaseObject . LocalName . Value ) ) { antiDepAsItemBinding . UpdateRefNameNamePart ( existingDatabaseObject . LocalName . Value , newName ) ; } } } }
Compares the two Dictionaries passed in and constructs a Dictionary mapping
any old DatabaseObjects which exist in both artifacts but whose name has changed
in the new artifact.
Compares the two Dictionaries passed in and constructs a Dictionary mapping any old DatabaseObjects which exist in both artifacts but whose name has changed in the new artifact .
// Note: byte-by-byte (Ordinal) compare is correct here - if name has changed ordinally want to change references too // Now update the name part of any ItemBinding which references the old name // Note: have to convert to array first to prevent exceptions due to // editing the collection while iterating over it
existingArtifactSSideMappings
Dictionary<DatabaseObject, T>
Dictionary mapping S-side database objects to their names in the existing artifact
Dictionary mapping S - side database objects to their names in the existing artifact
newArtifactSSideMappings
Dictionary<DatabaseObject, T>
Dictionary mapping S-side database objects to their names in the new artifact
Dictionary mapping S - side database objects to their names in the new artifact
typeparam
None