Beispiel #1
0
        public TableDiff Compare(Table t)
        {
            var diff = new TableDiff();

            diff.Owner = t.Owner;
            diff.Name  = t.Name;

            //get additions and compare mutual columns
            foreach (Column c in Columns.Items)
            {
                Column c2 = t.Columns.Find(c.Name);
                if (c2 == null)
                {
                    diff.ColumnsAdded.Add(c);
                }
                else
                {
                    //compare mutual columns
                    ColumnDiff cDiff = c.Compare(c2);
                    if (cDiff.IsDiff)
                    {
                        diff.ColumnsDiff.Add(cDiff);
                    }
                }
            }

            //get deletions
            foreach (Column c in t.Columns.Items.Where(c => Columns.Find(c.Name) == null))
            {
                diff.ColumnsDropped.Add(c);
            }

            //get added and compare mutual constraints
            foreach (Constraint c in Constraints)
            {
                Constraint c2 = t.FindConstraint(c.Name);
                if (c2 == null)
                {
                    diff.ConstraintsAdded.Add(c);
                }
                else
                {
                    if (c.Script() != c2.Script())
                    {
                        diff.ConstraintsChanged.Add(c);
                    }
                }
            }
            //get deleted constraints
            foreach (Constraint c in t.Constraints.Where(c => FindConstraint(c.Name) == null))
            {
                diff.ConstraintsDeleted.Add(c);
            }

            return(diff);
        }