mirror of
				https://github.com/nsnail/FreeSql.git
				synced 2025-10-31 15:55:27 +08:00 
			
		
		
		
	补充 DbFirst GetTablesByDatabase 获取表备注
This commit is contained in:
		| @@ -15,6 +15,10 @@ namespace FreeSql.DatabaseModel { | ||||
| 		/// </summary> | ||||
| 		public string Name { get; internal set; } | ||||
| 		/// <summary> | ||||
| 		/// 表备注,SqlServer下是扩展属性 MS_Description | ||||
| 		/// </summary> | ||||
| 		public string Comment { get; internal set; } | ||||
| 		/// <summary> | ||||
| 		/// 表/视图 | ||||
| 		/// </summary> | ||||
| 		public DbTableType Type { get; set; } | ||||
|   | ||||
| @@ -154,6 +154,7 @@ select | ||||
| concat(a.table_schema, '.', a.table_name) 'id', | ||||
| a.table_schema 'schema', | ||||
| a.table_name 'table', | ||||
| a.table_comment, | ||||
| a.table_type 'type' | ||||
| from information_schema.tables a | ||||
| where a.table_schema in ({0})", databaseIn); | ||||
| @@ -166,12 +167,13 @@ where a.table_schema in ({0})", databaseIn); | ||||
| 				var table_id = string.Concat(row[0]); | ||||
| 				var schema = string.Concat(row[1]); | ||||
| 				var table = string.Concat(row[2]); | ||||
| 				var type = string.Concat(row[3]) == "VIEW" ? DbTableType.VIEW : DbTableType.TABLE; | ||||
| 				var comment = string.Concat(row[3]); | ||||
| 				var type = string.Concat(row[4]) == "VIEW" ? DbTableType.VIEW : DbTableType.TABLE; | ||||
| 				if (database.Length == 1) { | ||||
| 					table_id = table_id.Substring(table_id.IndexOf('.') + 1); | ||||
| 					schema = ""; | ||||
| 				} | ||||
| 				loc2.Add(table_id, new DbTableInfo { Id = table_id, Schema = schema, Name = table, Type = type }); | ||||
| 				loc2.Add(table_id, new DbTableInfo { Id = table_id, Schema = schema, Name = table, Comment = comment, Type = type }); | ||||
| 				loc3.Add(table_id, new Dictionary<string, DbColumnInfo>()); | ||||
| 				switch (type) { | ||||
| 					case DbTableType.TABLE: | ||||
|   | ||||
| @@ -223,9 +223,12 @@ select | ||||
| b.nspname || '.' || a.tablename, | ||||
| a.schemaname, | ||||
| a.tablename , | ||||
| d.description, | ||||
| 'TABLE' | ||||
| from pg_tables a | ||||
| inner join pg_namespace b on b.nspname = a.schemaname | ||||
| inner join pg_class c on c.relnamespace = b.oid and c.relname = a.tablename | ||||
| left join pg_description d on d.objoid = c.oid and objsubid = 0 | ||||
| where a.schemaname not in ('pg_catalog', 'information_schema', 'topology') | ||||
| and b.nspname || '.' || a.tablename not in ('public.spatial_ref_sys') | ||||
|  | ||||
| @@ -235,9 +238,11 @@ select | ||||
| b.nspname || '.' || a.relname, | ||||
| b.nspname, | ||||
| a.relname, | ||||
| d.description, | ||||
| 'VIEW' | ||||
| from pg_class a | ||||
| inner join pg_namespace b on b.oid = a.relnamespace | ||||
| left join pg_description d on d.objoid = a.oid and objsubid = 0 | ||||
| where b.nspname not in ('pg_catalog', 'information_schema') and a.relkind in ('m','v')  | ||||
| and b.nspname || '.' || a.relname not in ('public.geography_columns','public.geometry_columns','public.raster_columns','public.raster_overviews') | ||||
| "; | ||||
| @@ -250,8 +255,9 @@ and b.nspname || '.' || a.relname not in ('public.geography_columns','public.geo | ||||
| 					var object_id = string.Concat(row[0]); | ||||
| 					var owner = string.Concat(row[1]); | ||||
| 					var table = string.Concat(row[2]); | ||||
| 					Enum.TryParse<DbTableType>(string.Concat(row[3]), out var type); | ||||
| 					loc2.Add(object_id, new DbTableInfo { Id = object_id.ToString(), Schema = owner, Name = table, Type = type }); | ||||
| 					var comment = string.Concat(row[3]); | ||||
| 					Enum.TryParse<DbTableType>(string.Concat(row[4]), out var type); | ||||
| 					loc2.Add(object_id, new DbTableInfo { Id = object_id.ToString(), Schema = owner, Name = table, Comment = comment, Type = type }); | ||||
| 					loc3.Add(object_id, new Dictionary<string, DbColumnInfo>()); | ||||
| 					switch (type) { | ||||
| 						case DbTableType.VIEW: | ||||
|   | ||||
| @@ -123,27 +123,33 @@ select | ||||
|  a.Object_id | ||||
| ,b.name 'Owner' | ||||
| ,a.name 'Name' | ||||
| ,c.value | ||||
| ,'TABLE' type | ||||
| from sys.tables a | ||||
| inner join sys.schemas b on b.schema_id = a.schema_id | ||||
| left join sys.extended_properties AS c ON c.major_id = a.object_id AND c.minor_id = 0 AND c.name = 'MS_Description' | ||||
| where not(b.name = 'dbo' and a.name = 'sysdiagrams') | ||||
| union all | ||||
| select | ||||
|  a.Object_id | ||||
| ,b.name 'Owner' | ||||
| ,a.name 'Name' | ||||
| ,c.value | ||||
| ,'VIEW' type | ||||
| from sys.views a | ||||
| inner join sys.schemas b on b.schema_id = a.schema_id | ||||
| left join sys.extended_properties AS c ON c.major_id = a.object_id AND c.minor_id = 0 AND c.name = 'MS_Description' | ||||
| union all | ||||
| select  | ||||
|  a.Object_id | ||||
| ,b.name 'Owner' | ||||
| ,a.name 'Name' | ||||
| ,c.value | ||||
| ,'StoreProcedure' type | ||||
| from sys.procedures a | ||||
| inner join sys.schemas b on b.schema_id = a.schema_id | ||||
| where a.type = 'P' and charindex('$NPSP', a.name) = 0 and charindex('diagram', a.name) = 0 | ||||
| left join sys.extended_properties AS c ON c.major_id = a.object_id AND c.minor_id = 0 AND c.name = 'MS_Description' | ||||
| where a.type = 'P' and charindex('diagram', a.name) = 0 | ||||
| order by type desc, b.name, a.name | ||||
| ; | ||||
| use [{olddatabase}]; | ||||
| @@ -157,8 +163,9 @@ use [{olddatabase}]; | ||||
| 					int object_id = int.Parse(string.Concat(row[0])); | ||||
| 					var owner = string.Concat(row[1]); | ||||
| 					var table = string.Concat(row[2]); | ||||
| 					Enum.TryParse<DbTableType>(string.Concat(row[3]), out var type); | ||||
| 					loc2.Add(object_id, new DbTableInfo { Id = object_id.ToString(), Schema = owner, Name = table, Type = type }); | ||||
| 					var comment = string.Concat(row[3]); | ||||
| 					Enum.TryParse<DbTableType>(string.Concat(row[4]), out var type); | ||||
| 					loc2.Add(object_id, new DbTableInfo { Id = object_id.ToString(), Schema = owner, Name = table, Comment = comment, Type = type }); | ||||
| 					loc3.Add(object_id, new Dictionary<string, DbColumnInfo>()); | ||||
| 					switch (type) { | ||||
| 						case DbTableType.VIEW: | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 28810
					28810