public virtual async Task <DiagnoseResult> DiagnoseSelfReferenceSame()
        {
            this.Feedback("Begin to diagnose self reference with same value...");

            DiagnoseResult result = new DiagnoseResult();

            DbInterpreterOption option = new DbInterpreterOption()
            {
                ObjectFetchMode = DatabaseObjectFetchMode.Details
            };

            DbInterpreter interpreter = DbInterpreterHelper.GetDbInterpreter(this.DatabaseType, this.connectionInfo, option);

            this.Feedback("Begin to get foreign keys...");

            List <TableForeignKey> foreignKeys = await interpreter.GetTableForeignKeysAsync();

            this.Feedback("End get foreign keys.");

            var groups = foreignKeys.Where(item => item.ReferencedTableName == item.TableName)
                         .GroupBy(item => new { item.Owner, item.TableName });

            using (DbConnection dbConnection = interpreter.CreateConnection())
            {
                foreach (var group in groups)
                {
                    foreach (TableForeignKey foreignKey in group)
                    {
                        string countSql = this.GetTableColumnReferenceSql(interpreter, foreignKey, true);

                        this.Feedback($@"Begin to get invalid record count for foreign key ""{foreignKey.Name}"" of table ""{foreignKey.TableName}""...");

                        int count = Convert.ToInt32(await interpreter.GetScalarAsync(dbConnection, countSql));

                        this.Feedback($@"End get invalid record count for column ""{foreignKey.Name}"" of table ""{foreignKey.TableName}"", the count is {count}.");

                        if (count > 0)
                        {
                            result.Details.Add(new DiagnoseResultItem()
                            {
                                DatabaseObject = foreignKey,
                                RecordCount    = count,
                                Sql            = this.GetTableColumnReferenceSql(interpreter, foreignKey, false)
                            });
                        }
                    }
                }
            }

            this.Feedback("End diagnose self reference with same value.");

            return(result);
        }
        private async void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
        {
            TabPage tabPage = this.tabControl1.SelectedTab;

            if (tabPage == null)
            {
                return;
            }

            Table table = new Table()
            {
                Owner = this.cboOwner.Text, Name = this.txtTableName.Text.Trim()
            };

            DbInterpreter dbInterpreter = this.GetDbInterpreter();

            if (tabPage.Name == this.tabIndexes.Name)
            {
                tabPage.Tag = 1;

                this.ucIndexes.Table = table;

                if (!this.ucIndexes.Inited)
                {
                    this.ucIndexes.InitControls(dbInterpreter);
                }

                if (!this.displayInfo.IsNew)
                {
                    if (!this.ucIndexes.LoadedData)
                    {
                        SchemaInfoFilter filter = new SchemaInfoFilter();
                        filter.TableNames = new string[] { this.displayInfo.Name };

                        List <TableIndex> tableIndexes = await dbInterpreter.GetTableIndexesAsync(filter, true);

                        this.ucIndexes.LoadIndexes(IndexManager.GetIndexDesignerInfos(this.displayInfo.DatabaseType, tableIndexes));
                    }
                }

                IEnumerable <TableColumnDesingerInfo> columns = this.ucColumns.GetColumns().Where(item => !string.IsNullOrEmpty(item.Name) && item.IsPrimary);

                this.ucIndexes.LoadPrimaryKeys(columns);
            }
            else if (tabPage.Name == this.tabForeignKeys.Name)
            {
                tabPage.Tag = 1;

                this.ucForeignKeys.Table = table;

                if (!this.ucForeignKeys.Inited)
                {
                    dbInterpreter.Option.ObjectFetchMode = DatabaseObjectFetchMode.Simple;

                    List <Table> tables = await dbInterpreter.GetTablesAsync();

                    if (this.displayInfo.IsNew)
                    {
                        tables.Add(new Table()
                        {
                            Name = "<self>"
                        });
                    }

                    this.ucForeignKeys.InitControls(tables);
                }

                if (!this.displayInfo.IsNew)
                {
                    if (!this.ucForeignKeys.LoadedData)
                    {
                        SchemaInfoFilter filter = new SchemaInfoFilter();
                        filter.TableNames = new string[] { this.displayInfo.Name };

                        dbInterpreter.Option.ObjectFetchMode = DatabaseObjectFetchMode.Details;

                        List <TableForeignKey> foreignKeys = await dbInterpreter.GetTableForeignKeysAsync(filter);

                        this.ucForeignKeys.LoadForeignKeys(IndexManager.GetForeignKeyDesignerInfos(foreignKeys));
                    }
                }
            }
            else if (tabPage.Name == this.tabConstraints.Name)
            {
                tabPage.Tag = 1;

                if (!this.ucConstraints.Inited)
                {
                    this.ucConstraints.InitControls();
                }

                if (!this.displayInfo.IsNew)
                {
                    if (!this.ucConstraints.LoadedData)
                    {
                        SchemaInfoFilter filter = new SchemaInfoFilter();
                        filter.TableNames = new string[] { this.displayInfo.Name };

                        List <TableConstraint> constraints = await dbInterpreter.GetTableConstraintsAsync(filter);

                        this.ucConstraints.LoadConstraints(IndexManager.GetConstraintDesignerInfos(constraints));
                    }
                }
            }
        }