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.ScriptCreate() != c2.ScriptCreate())
                    {
                        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);
        }
Beispiel #2
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 (var c in Columns.Items) {
				var c2 = t.Columns.Find(c.Name);
				if (c2 == null) {
					diff.ColumnsAdded.Add(c);
				} else {
					//compare mutual columns
					var cDiff = c.Compare(c2);
					if (cDiff.IsDiff) {
						diff.ColumnsDiff.Add(cDiff);
					}
				}
			}

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

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

			return diff;
		}
Beispiel #3
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 (var c in Columns.Items)
            {
                var c2 = t.Columns.Find(c.Name);
                if (c2 == null)
                {
                    diff.ColumnsAdded.Add(c);
                }
                else
                {
                    //compare mutual columns
                    var cDiff = c.Compare(c2);
                    if (cDiff.IsDiff)
                    {
                        diff.ColumnsDiff.Add(cDiff);
                    }
                }
            }

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

            if (!t.IsType)
            {
                //get added and compare mutual constraints
                foreach (var c in Constraints)
                {
                    var c2 = t.FindConstraint(c.Name);
                    if (c2 == null)
                    {
                        diff.ConstraintsAdded.Add(c);
                    }
                    else
                    {
                        if (c.ScriptCreate() != c2.ScriptCreate())
                        {
                            diff.ConstraintsChanged.Add(c);
                        }
                    }
                }
                //get deleted constraints
                foreach (var c in t.Constraints.Where(c => FindConstraint(c.Name) == null))
                {
                    diff.ConstraintsDeleted.Add(c);
                }
            }
            else
            {
                // compare constraints on table types, which can't be named in the script, but have names in the DB
                var dest = Constraints.ToList();
                var src  = t.Constraints.ToList();

                var j = from c1 in dest
                        join c2 in src on c1.ScriptCreate() equals c2.ScriptCreate() into match                         //new { c1.Type, c1.Unique, c1.Clustered, Columns = string.Join(",", c1.Columns.ToArray()), IncludedColumns = string.Join(",", c1.IncludedColumns.ToArray()) } equals new { c2.Type, c2.Unique, c2.Clustered, Columns = string.Join(",", c2.Columns.ToArray()), IncludedColumns = string.Join(",", c2.IncludedColumns.ToArray()) } into match
                        from m in match.DefaultIfEmpty()
                        select new { c1, m };

                foreach (var c in j)
                {
                    if (c.m == null)
                    {
                        diff.ConstraintsAdded.Add(c.c1);
                    }
                    else
                    {
                        src.Remove(c.m);
                    }
                }
                foreach (var c in src)
                {
                    diff.ConstraintsDeleted.Add(c);
                }
            }

            return(diff);
        }
Beispiel #4
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 (var c in Columns.Items) {
				var c2 = t.Columns.Find(c.Name);
				if (c2 == null) {
					diff.ColumnsAdded.Add(c);
				} else {
					//compare mutual columns
					var cDiff = c.Compare(c2);
					if (cDiff.IsDiff) {
						diff.ColumnsDiff.Add(cDiff);
					}
				}
			}

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

			if (!t.IsType) {
				//get added and compare mutual constraints
				foreach (var c in Constraints) {
					var c2 = t.FindConstraint(c.Name);
					if (c2 == null) {
						diff.ConstraintsAdded.Add(c);
					} else {
						if (c.ScriptCreate() != c2.ScriptCreate()) {
							diff.ConstraintsChanged.Add(c);
						}
					}
				}
				//get deleted constraints
				foreach (var c in t.Constraints.Where(c => FindConstraint(c.Name) == null)){
					diff.ConstraintsDeleted.Add(c);
				}
			} else {
				// compare constraints on table types, which can't be named in the script, but have names in the DB
				var dest = Constraints.ToList();
				var src = t.Constraints.ToList();

				var j = from c1 in dest
						join c2 in src on c1.ScriptCreate() equals c2.ScriptCreate() into match //new { c1.Type, c1.Unique, c1.Clustered, Columns = string.Join(",", c1.Columns.ToArray()), IncludedColumns = string.Join(",", c1.IncludedColumns.ToArray()) } equals new { c2.Type, c2.Unique, c2.Clustered, Columns = string.Join(",", c2.Columns.ToArray()), IncludedColumns = string.Join(",", c2.IncludedColumns.ToArray()) } into match
						from m in match.DefaultIfEmpty()
						select new { c1, m };

				foreach (var c in j) {
					if (c.m == null) {
						diff.ConstraintsAdded.Add(c.c1);
					} else {
						src.Remove(c.m);
					}
				}
				foreach (var c in src) {
					diff.ConstraintsDeleted.Add(c);
				}
			}

			return diff;
		}