nHydrate.Generator.Models.Relation.Equals C# (CSharp) Method

Equals() public method

public Equals ( object obj ) : bool
obj object
return bool
        public override bool Equals(object obj)
        {
            try
            {
                if (!(obj is Relation)) return false;
                var relationOther = (Relation)obj;

                if (this.IsInvalidRelation()) return false;
                if (relationOther.IsInvalidRelation()) return false;

                #region Check Parents
                var parentTableName1 = ((Table)this.ParentTableRef.Object).Name;
                var parentTableName2 = ((Table)relationOther.ParentTableRef.Object).Name;

                var list1 = new SortedDictionary<string, ColumnRelationship>();
                foreach (ColumnRelationship cr in this.ColumnRelationships)
                {
                    if (cr.ChildColumnRef.Object != null)
                    {
                        var column = (Column)cr.ChildColumnRef.Object;
                        if (!list1.ContainsKey(column.Name))
                            list1.Add(column.Name, cr);
                    }
                }

                var list2 = new SortedDictionary<string, ColumnRelationship>();
                foreach (ColumnRelationship cr in relationOther.ColumnRelationships)
                {
                    if (cr.ChildColumnRef.Object != null)
                    {
                        var column = (Column)cr.ChildColumnRef.Object;
                        if (!list2.ContainsKey(column.Name))
                            list2.Add(((Column)cr.ChildColumnRef.Object).Name, cr);
                    }
                }

                var parentColName1 = string.Empty;
                foreach (var key in list1.Keys)
                {
                    parentColName1 += key;
                }

                var parentColName2 = string.Empty;
                foreach (var key in list2.Keys)
                {
                    parentColName2 += key;
                }
                #endregion

                #region Check Children
                var childTableName1 = ((Table)this.ChildTableRef.Object).Name;
                var childTableName2 = ((Table)relationOther.ChildTableRef.Object).Name;

                var list3 = new SortedDictionary<string, ColumnRelationship>();
                foreach (ColumnRelationship cr in this.ColumnRelationships)
                {
                    if (cr.ParentColumnRef.Object != null)
                    {
                        var column = (Column)cr.ParentColumnRef.Object;
                        if (!list3.ContainsKey(column.Name))
                            list3.Add(column.Name, cr);
                    }
                }

                var list4 = new SortedDictionary<string, ColumnRelationship>();
                foreach (ColumnRelationship cr in relationOther.ColumnRelationships)
                {
                    if (cr.ParentColumnRef.Object != null)
                    {
                        var column = (Column)cr.ParentColumnRef.Object;
                        if (!list4.ContainsKey(column.Name))
                            list4.Add(column.Name, cr);
                    }
                }

                var childColName1 = string.Empty;
                foreach (var key in list3.Keys)
                {
                    childColName1 += key;
                }

                var childColName2 = string.Empty;
                foreach (var key in list4.Keys)
                {
                    childColName2 += key;
                }
                #endregion

                //string parentCol
                return (parentTableName1 == parentTableName2) &&
                    (parentColName1 == parentColName2) &&
                    (childTableName1 == childTableName2) &&
                    (childColName1 == childColName2);
            }
            catch (Exception ex)
            {
                throw;
            }

        }