public List<DatabaseItemComparison> addComparisonDetails(EADatabaseItemComparison comparedItem)
 {
     List<DatabaseItemComparison> addedComparedItems = new List<DatabaseItemComparison>();
     var existingTable = comparedItem.existingDatabaseItem as Table;
     var newTable = comparedItem.newDatabaseItem as Table;
     if (existingTable != null)
     {
         List<Column> alreadMappedcolumns = new List<Column>();
         //add all existing columns
         foreach (Column existingColumn in existingTable.columns.OrderBy(x => x.position))
         {
             Column newColumn = null;
             if (newTable != null)
             {
                 newColumn = newTable.getCorrespondingColumn(existingColumn,alreadMappedcolumns);
                 alreadMappedcolumns.Add(newColumn);
             }
             addedComparedItems.Add(comparedItem.addOwnedComparison(newColumn,existingColumn));
         }
         //now the new columns that don't have a corresponding existing column
         if (newTable != null)
         {
             List<Column> columnsToDelete = new List<Column>();
             foreach (Column newColumn in newTable.columns)
             {
                 //if not already mapped
                 if (addedComparedItems.All(x => x.newDatabaseItem != newColumn))
                 {
                     //and there is no other column with the same name that maps to the same physical column and has exactly the same properties and name
                     var newColumnsToDelete = addedComparedItems.Where(y =>
                                                 y.existingDatabaseItem != null
                                                 && y.existingDatabaseItem.logicalElements.Contains(newColumn.logicalElement)
                                                 && y.newDatabaseItem != null
                                                 && y.newDatabaseItem.name == newColumn.name
                                                 && y.newDatabaseItem.properties == newColumn.properties)
                                                 .Select(z => z.newDatabaseItem as Column);
                     if (newColumnsToDelete.Any())
                     {
                         columnsToDelete.AddRange(newColumnsToDelete);
                     }
                     else
                     {
                         //no duplicates so add to the comparison
                         addedComparedItems.Add(comparedItem.addOwnedComparison(newColumn, null));
                     }
                 }
             }
             //delete the columns that were identified as duplicates
             foreach (var columnToDelete in columnsToDelete)
             {
                 columnToDelete.delete();
             }
         }
         //add all existing constraints
         foreach (var existingConstraint in existingTable.constraints)
         {
             Constraint newConstraint = null;
             if (newTable != null)
             {
                 if (existingConstraint is ForeignKey)
                 {
                     newConstraint = newTable.getCorrespondingForeignKey((ForeignKey)existingConstraint);
                 }
                 else
                 {
                     newConstraint = (Constraint)newTable.primaryKey ;
                 }
                 addedComparedItems.Add(comparedItem.addOwnedComparison(newConstraint,existingConstraint));
             }
         }
         //then add the new constraints don't have a corresponding existing constraint
         if (newTable != null)
         {
             foreach (var newConstraint in newTable.constraints)
             {
                 if (! addedComparedItems.Any(x => x.newDatabaseItem == newConstraint))
                 {
                     addedComparedItems.Add(comparedItem.addOwnedComparison(newConstraint, null));
                 }
             }
         }
     }
     else
     {
         //no existing table, everything is new
         foreach (var newColumn in newTable.columns)
         {
             addedComparedItems.Add(comparedItem.addOwnedComparison(newColumn,null));
         }
         foreach (var newConstraint in newTable.constraints)
         {
             addedComparedItems.Add(comparedItem.addOwnedComparison(newConstraint,null));
         }
     }
     return addedComparedItems;
 }
 private void addTableComparison(EADatabaseItemComparison tableComparison)
 {
     addToComparison(tableComparison);
     var tableComparisons = this.addComparisonDetails(tableComparison);
     //add them to the comparison
     addToComparison(tableComparisons);
 }