Ejemplo n.º 1
0
        /// <summary>
        /// Migration reference from destination to source
        /// </summary>
        /// <param name="manager"></param>
        /// <param name="sourceDatabase"></param>
        /// <param name="destinationDatabase"></param>
        private void MigrationReference(MappingManager manager, SourceDatabase sourceDatabase, DestinationDatabase destinationDatabase)
        {
            List <string> listSourceTableName = sourceDatabase.GetListTable();
            List <string> listDestTableName   = destinationDatabase.GetListTable();

            foreach (string sourceTableName in listSourceTableName)
            {
                //
                // Check does it rename or not ?
                string destTableName = manager.GetTableNewName(sourceTableName);
                LogService.Log.Info("Migrate from " + destTableName + " to " + sourceTableName);


                //
                // Then check, it's still exist in destination database or not
                if (listDestTableName.Contains(destTableName) == false)
                {
                    LogService.Log.Info("Table " + sourceTableName + " has been dropped in destination database.");
                    continue;
                }


                //
                // Get MapTable (class contains information about table, includes references)
                MapTable sourceMapTable = sourceDatabase.GetMapTable(sourceTableName);
                MapTable destMapTable   = destinationDatabase.GetMapTable(destTableName);


                //
                // Add references
                List <ReferenceInformation> listDestReference = destMapTable.GetReference();
                foreach (ReferenceInformation reference in listDestReference)
                {
                    //
                    // Try to revert from new name of table to old name of table
                    string PKTableOldName = manager.GetTableOldName(reference.PKTableName);
                    string FKTableOldName = manager.GetTableOldName(reference.FKTableName);
                    reference.PKTableName = PKTableOldName;
                    reference.FKTableName = FKTableOldName;


                    //
                    // Add new reference information to sourceMapTable
                    if (sourceMapTable.HasReference(reference) == false)
                    {
                        LogService.Log.Info("Add new reference from " + reference.FKTableName + "(" + reference.FKColumnName + ")" +
                                            "to " + reference.FKTableName + "(" + reference.FKColumnName + ")");
                        sourceMapTable.AddReference(reference);
                    }
                }
            }
        }