CodeSmith无法获取MySQL表及列Description说明处理
实体类生成模板下载:
链接:https://pan.baidu.com/s/1tLxW5m5ECwVV2feWSVtQIA
提取码:qezw
反编译工具下载:
链接:https://pan.baidu.com/s/19dG4NweQodLl0yG5XQrcOg
提取码:r793
一、使用反编译工具dnSpy打开D:\software\generator71(1)\generator-71\SchemaProviders\SchemaExplorer.MySQLSchemaProvider.dll
二、找到MySQLSchemaProvider类
三、找到GetExtendedProperties方法名,使用反编译工具编辑该类,替换GetExtendedProperties的代码逻辑并进行保存
public ExtendedProperty[] GetExtendedProperties(string connectionString, SchemaObjectBase schemaObject) { List<ExtendedProperty> list = new List<ExtendedProperty>(); if (schemaObject is ColumnSchema) { ColumnSchema columnSchema = schemaObject as ColumnSchema; string commandText = string.Format("SELECT EXTRA, COLUMN_DEFAULT, COLUMN_TYPE, COLUMN_COMMENT\r\n FROM INFORMATION_SCHEMA.COLUMNS\r\n WHERE TABLE_SCHEMA = '{0}' AND TABLE_NAME = '{1}' AND COLUMN_NAME = '{2}'", columnSchema.Table.Database.Name, columnSchema.Table.Name, columnSchema.Name); using (DbConnection dbConnection = MySQLSchemaProvider.CreateConnection(connectionString)) { dbConnection.Open(); DbCommand dbCommand = dbConnection.CreateCommand(); dbCommand.CommandText = commandText; dbCommand.Connection = dbConnection; using (IDataReader dataReader = dbCommand.ExecuteReader(CommandBehavior.CloseConnection)) { while (dataReader.Read()) { string text = dataReader.GetString(0).ToLower(); bool flag = dataReader.IsDBNull(1); string value = ""; if (!flag) { value = dataReader.GetString(1).ToUpper(); } string value2 = dataReader.GetString(2).ToUpper(); string @string = dataReader.GetString(3); bool flag2 = text.IndexOf("auto_increment") > -1; list.Add(new ExtendedProperty("CS_IsIdentity", flag2, columnSchema.DataType)); if (flag2) { list.Add(new ExtendedProperty("CS_IdentitySeed", 1, columnSchema.DataType)); list.Add(new ExtendedProperty("CS_IdentityIncrement", 1, columnSchema.DataType)); } list.Add(new ExtendedProperty("CS_ColumnDefaultIsNull", flag, DbType.Boolean)); list.Add(new ExtendedProperty("CS_Default", value, DbType.String)); list.Add(new ExtendedProperty("CS_ColumnDefault", value, DbType.String)); list.Add(new ExtendedProperty("CS_SystemType", value2, DbType.String)); list.Add(new ExtendedProperty("CS_ColumnType", value2, DbType.String)); list.Add(new ExtendedProperty("CS_ColumnExtra", text.ToUpper(), DbType.String)); list.Add(new ExtendedProperty("CS_Description", @string, DbType.String)); } if (!dataReader.IsClosed) { dataReader.Close(); } } if (dbConnection.State != ConnectionState.Closed) { dbConnection.Close(); } } } if (schemaObject is TableSchema) { TableSchema tableSchema = schemaObject as TableSchema; string commandText2 = string.Format("SHOW CREATE TABLE `{0}`.`{1}`", tableSchema.Database.Name, tableSchema.Name); using (DbConnection dbConnection2 = MySQLSchemaProvider.CreateConnection(connectionString)) { dbConnection2.Open(); DbCommand dbCommand2 = dbConnection2.CreateCommand(); dbCommand2.CommandText = commandText2; dbCommand2.Connection = dbConnection2; using (IDataReader dataReader2 = dbCommand2.ExecuteReader(CommandBehavior.CloseConnection)) { while (dataReader2.Read()) { string string2 = dataReader2.GetString(1); list.Add(new ExtendedProperty("TS_Description", string2, DbType.String)); int num = string2.LastIndexOf("ENGINE"); int num2 = string2.LastIndexOf("COMMENT="); string value3 = dataReader2.GetString(0); if (num2 > num) { value3 = string2.Substring(num2 + 9).Replace("'", ""); } list.Add(new ExtendedProperty("CS_Description", value3, DbType.String)); } if (!dataReader2.IsClosed) { dataReader2.Close(); } } if (dbConnection2.State != ConnectionState.Closed) { dbConnection2.Close(); } } } return list.ToArray(); }
四、生成效果
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· 展开说说关于C#中ORM框架的用法!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?