コード例 #1
0
 public OperateResult <IEnumerable <TableStructureDto> > GetDatabaseTableStructure(int dbId)
 {
     return(OperateUtil.Execute(() =>
     {
         var dbInfo = GetDatabaseConfigs().Value.Find(x => x.Id == dbId);
         if (dbInfo != null && !string.IsNullOrWhiteSpace(dbInfo.ConnectionString) && !string.IsNullOrWhiteSpace(dbInfo.DbType))
         {
             var dbType = Enum.Parse <DatabaseType>(dbInfo.DbType);
             var selectTableListSql = SqlQueryUtil.GetQueryTableListSql(dbType, dbInfo.DbName);
             var selectTableColumnListSql = SqlQueryUtil.GetQueryTableColumnListSql(dbType, dbInfo.DbName);
             using (var dataAccess = DataAccessFactory.GetDataAccess(dbType, dbInfo.ConnectionString, false))
             {
                 var tableSqlquery = new SqlQuery(selectTableListSql);
                 var tableList = dataAccess.Query <TableStructureDto>(tableSqlquery);
                 var tableColumnSqlQuery = new SqlQuery(selectTableColumnListSql);
                 var tableColumnList = dataAccess.Query <TableColumnStructureDto>(tableColumnSqlQuery);
                 foreach (var item in tableList)
                 {
                     item.ColumnList = tableColumnList.Where(m => m.TableName == item.TableName);
                 }
                 return tableList;
             }
         }
         return null;
     }, callMemberName: "DataBaseConfigRespository-GetDatabaseTableStructure"));
 }
コード例 #2
0
        /// <summary>
        /// 获取表结构列表
        /// </summary>
        /// <param name="dbID">数据库ID</param>
        /// <returns>表结构列表</returns>
        public async Task <IEnumerable <TableStructureDto> > GetTableStructureListAsync(int dbID)
        {
            var dbInfo = await GetInfoAsync(m => m.FID == dbID && m.FIsDeleted == false);

            if (dbInfo != null && dbInfo.FConnection.IsNotNullAndNotEmptyWhiteSpace() && dbInfo.FDbType.IsNotNullAndNotEmptyWhiteSpace())
            {
                var dbType                   = Enum.Parse <DatabaseType>(dbInfo.FDbType);
                var selectTableListSql       = SqlQueryUtil.GetQueryTableListSql(dbType, dbInfo.FName);
                var selectTableColumnListSql = SqlQueryUtil.GetQueryTableColumnListSql(dbType, dbInfo.FName);
                using (var dataAccess = DataAccessFactory.GetDataAccess(dbType, dbInfo.FConnection, isWriter: false))
                {
                    var tableSqlquery = new SqlQuery(selectTableListSql);
                    var tableList     = await dataAccess.QueryAsync <TableStructureDto>(tableSqlquery);

                    var tableColumnSqlQuery = new SqlQuery(selectTableColumnListSql);
                    var tableColumnList     = await dataAccess.QueryAsync <TableColumnStructureDto>(tableColumnSqlQuery);

                    foreach (var item in tableList)
                    {
                        item.ColumnList = tableColumnList.Where(m => m.TableName == item.TableName);
                    }
                    return(tableList);
                }
            }
            return(null);
        }