/// <summary> /// 获取表信息 /// </summary> /// <param name="oper"></param> /// <param name="info"></param> /// <param name="tableNames"></param> /// <returns></returns> public List <DBTableInfo> GetTablesInfo(DataBaseOperate oper, DBInfo info, IEnumerable <string> tableNames) { Dictionary <string, DBTableInfo> dicTables = new Dictionary <string, DBTableInfo>(); List <DBTableInfo> lst = GetTableNames(oper, info, tableNames); DataTable dtSchema = oper.GetSchema("Columns"); DataTable dtDataTypes = oper.GetSchema("DataTypes"); foreach (DBTableInfo table in lst) { dicTables[table.Name] = table; table.Params = new List <EntityParam>(); table.RelationItems = new List <TableRelationAttribute>(); } foreach (DataRow dr in dtSchema.Rows) { string tableName = dr["TABLE_NAME"] as string; if (string.IsNullOrEmpty(tableName)) { continue; } DBTableInfo table = null; if (dicTables.TryGetValue(tableName, out table)) { FillParam(table, dr, dtDataTypes); } } List <TableRelationAttribute> lstRelation = GetRelation(oper, info, tableNames); Buffalo.DB.DataBaseAdapter.SqlServer2KAdapter.DBStructure.FillRelation(dicTables, lstRelation); return(lst); }
/// <summary> /// 获取所有关系 /// </summary> /// <param name="oper"></param> /// <param name="info"></param> /// <param name="childName"></param> /// <returns></returns> public List <TableRelationAttribute> GetRelation(DataBaseOperate oper, DBInfo info, IEnumerable <string> childName) { return(null); DataTable dtRelation = oper.GetSchema("ForeignKeys"); List <TableRelationAttribute> lstRet = new List <TableRelationAttribute>(); foreach (DataRow row in dtRelation.Rows) { TableRelationAttribute tr = new TableRelationAttribute(); tr.Name = row["CONSTRAINT_NAME"] as string; tr.SourceName = row["FKEY_FROM_COLUMN"] as string; tr.SourceTable = row["TABLE_NAME"] as string; tr.TargetName = row["FKEY_TO_COLUMN"] as string; tr.TargetTable = row["FKEY_TO_TABLE"] as string; tr.IsParent = true; lstRet.Add(tr); tr = new TableRelationAttribute(); tr.Name = row["CONSTRAINT_NAME"] as string; tr.TargetName = row["FKEY_FROM_COLUMN"] as string; tr.TargetTable = row["TABLE_NAME"] as string; tr.SourceName = row["FKEY_TO_COLUMN"] as string; tr.SourceTable = row["FKEY_TO_TABLE"] as string; tr.IsParent = false; lstRet.Add(tr); } return(lstRet); }