private bool TableObject_ForeignKeyAdded(object sender, ColumnObjectModel column)
        {
            try
            {
                TableObject table = (TableObject)sender;

                List <string> exixtingRelations = table.ColumnRelationModel.Keys.ToList();

                table.InitializeColumnRemations();

                foreach (KeyValuePair <string, DatabaseRelation> relationPair in table.ColumnRelationModel)
                {
                    if (this.columnRelationModel.ContainsKey(relationPair.Key))
                    {
                        continue;
                    }

                    this.columnRelationModel.Add(relationPair.Key, relationPair.Value);
                }

                UIElement[] tableControls = this.FindVisualControls(typeof(TableObject));

                string dictionaryKey = table.ColumnRelationModel.Keys.FirstOrDefault(ex => !exixtingRelations.Contains(ex));

                this.DrawRelation(table, tableControls, new KeyValuePair <string, DatabaseRelation>(dictionaryKey, table.ColumnRelationModel[dictionaryKey]));

                return(true);
            }
            catch
            {
                return(false);
            }
        }
        public void RefreshTableRelations(TableModel tableModel)
        {
            TableObject[] tablesArray = this.FindVisualControls(typeof(TableObject)).TryCast <TableObject>();

            TableObject table = tablesArray.FirstOrDefault(t => t.Table.TableName == tableModel.TableName);

            if (table == null)
            {
                return;
            }

            KeyValuePair <string, DatabaseRelation>[] existingRelation = table.ColumnRelationModel.ToArray();

            foreach (KeyValuePair <string, DatabaseRelation> relation in existingRelation)
            {
                this.DatabaseRelation_Delete(relation.Value);

                if (this.columnRelationModel.ContainsKey(relation.Key))
                {
                    this.columnRelationModel.Remove(relation.Key);
                }
            }

            table.InitializeColumnRemations();

            UIElement[] tableControls = this.FindVisualControls(typeof(TableObject));

            foreach (KeyValuePair <string, DatabaseRelation> relation in table.ColumnRelationModel)
            {
                relation.Value.DatabaseRelationDelete += this.DatabaseRelation_Delete;

                this.columnRelationModel.Add(relation.Key, relation.Value);

                this.DrawRelation(table, tableControls, relation);
            }

            this.RedrawTableRelations(table);
        }