示例#1
0
 public void save()
 {
     //both existing and new database should exist to even begin
     if (_existingDatabase == null || _newDatabase == null)
     {
         throw new Exception("Both existign and new database should exist in order to save the database!");
     }
     //first save all tables
     foreach (var tableCompareItem in this.comparedItems.Where(x => x.itemType.Equals("Table", StringComparison.InvariantCultureIgnoreCase)))
     {
         tableCompareItem.save(_existingDatabase);
     }
     //then save all columns
     foreach (var columnCompareItem in this.comparedItems.Where(x => x.itemType.Equals("Column", StringComparison.InvariantCultureIgnoreCase)))
     {
         columnCompareItem.save(_existingDatabase);
     }
     //then save all primary keys
     foreach (var PKCompareItem in this.comparedItems.Where(x => x.itemType.Equals("Primary Key", StringComparison.InvariantCultureIgnoreCase)))
     {
         PKCompareItem.save(_existingDatabase);
     }
     //then save all foreign keys
     foreach (var FKCompareItem in this.comparedItems.Where(x => x.itemType.Equals("Foreign Key", StringComparison.InvariantCultureIgnoreCase)))
     {
         FKCompareItem.save(_existingDatabase);
     }
     //refresh model in gui
     this._existingDatabase._wrappedPackage.refresh();
 }
示例#2
0
        public void save()
        {
            //both existing and new database should exist to even begin
            if (_existingDatabase == null || _newDatabase == null)
            {
                throw new Exception("Both existing and new database should exist in order to save the database!");
            }
            //first save all valid tables
            var tableComparers = this.comparedItems.Where(x => x.itemType.Equals("Table", StringComparison.InvariantCultureIgnoreCase) &&
                                                          (x.newDatabaseItem == null ||
                                                           x.newDatabaseItem.isValid));

            foreach (var tableCompareItem in tableComparers)
            {
                tableCompareItem.save(_existingDatabase);
            }
            //loop each valid table again and save its columns, setting the correct order
            foreach (var tableCompareItem in tableComparers)
            {
                //then save all columns
                int i = 0;
                foreach (var columnCompareItem in tableCompareItem.ownedComparisons.Where(
                             x => x.itemType.Equals("Column", StringComparison.InvariantCultureIgnoreCase)))
                {
                    columnCompareItem.updatePosition(i);
                    columnCompareItem.save(_existingDatabase);
                    i++;
                }
            }

            //then save all primary keys
            foreach (var PKCompareItem in this.comparedItems.Where(x => x.itemType.Equals("Primary Key", StringComparison.InvariantCultureIgnoreCase) &&
                                                                   (x.newDatabaseItem == null || (x.newDatabaseItem.isValid && x.newDatabaseItem.owner.isValid))))
            {
                PKCompareItem.save(_existingDatabase);
            }
            //then save all foreign keys
            foreach (var FKCompareItem in this.comparedItems.Where(x => x.itemType.Equals("Foreign Key", StringComparison.InvariantCultureIgnoreCase) &&
                                                                   (x.newDatabaseItem == null || (x.newDatabaseItem.isValid && x.newDatabaseItem.owner.isValid))))
            {
                FKCompareItem.save(_existingDatabase);
            }

            //refresh model in gui
            this._existingDatabase._wrappedPackage.refresh();
        }