/// <inheritdoc />
        public IEnumerable <IDbTableEntity> GetTables(IDbDatabaseEntity database)
        {
            ISqlObject          table       = new SqlServerSource(new SqlServerSource("INFORMATION_SCHEMA"), "TABLES");
            ISqlObject          nameField   = new SqlServerField(table, "TABLE_NAME", null);
            ISqlObject          schemaField = new SqlServerField(table, "TABLE_SCHEMA", null);
            ISqlObject          typeField   = new SqlServerField(table, "TABLE_TYPE", null);
            ISqlSelectStatement statement   = new SqlServerSelectStatement();

            statement.FromClause.Source     = table;
            statement.WhereClause.Condition = typeField.Equal(new SqlServerConstantExpressionFactory().Create("BASE TABLE"));
            statement.SelectClause.AddExpressions(nameField);
            statement.SelectClause.AddExpressions(schemaField);

            SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();

            builder.DataSource     = database.Source.Name;
            builder.InitialCatalog = database.Name;
            if (!(builder.IntegratedSecurity = database.Source.DbCredential.IntegratedSecurity))
            {
                builder.UserID   = database.Source.DbCredential.UserName;
                builder.Password = database.Source.DbCredential.Password;
            }

            ICollection <IDbTableEntity> tables = new List <IDbTableEntity>();

            using (IDataReader reader = SqlHelper.ExecuteSelect(new SqlConnection(builder.ConnectionString), statement)) {
                while (reader.Read())
                {
                    tables.Add(new SqlServerTableEntity(database, reader.GetString(0), reader.GetString(1), new SqlServerTableFieldProvider()));
                }
            }
            return(tables);
        }
        /// <inheritdoc />
        public IEnumerable <IDbDatabaseEntity> GetDatabases(IDbSourceEntity source)
        {
            ISqlObject          table     = new SqlServerSource(new SqlServerSource("sys"), "databases");
            ISqlObject          nameField = new SqlServerField(table, "name", null);
            ISqlObject          ownerID   = new SqlServerField(table, "owner_sid", null);
            ISqlSelectStatement statement = new SqlServerSelectStatement();

            statement.FromClause.Source     = table;
            statement.WhereClause.Condition = ownerID.Equal(new SqlServerConstantExpressionFactory().Create(new byte[] { 0x01 })).Not();
            statement.SelectClause.AddExpressions(nameField);

            SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();

            builder.DataSource = source.Name;
            if (!(builder.IntegratedSecurity = source.DbCredential.IntegratedSecurity))
            {
                builder.UserID   = source.DbCredential.UserName;
                builder.Password = source.DbCredential.Password;
            }

            ICollection <IDbDatabaseEntity> databases = new List <IDbDatabaseEntity>();

            using (IDataReader reader = SqlHelper.ExecuteSelect(new SqlConnection(builder.ConnectionString), statement)) {
                while (reader.Read())
                {
                    databases.Add(new DbDatabaseEntity(source, reader.GetString(statement.SelectClause.Expressions.IndexOf(nameField)), new SqlServerDataEntityProvider()));
                }
            }
            return(databases);
        }