CodeSmith7链接Mysql

因为CodeSmith链接MySql的dll有点小Bug,没法获取表和列的描述信息,因此,须要从新修改驱动程序。mysql

如上图所示,CodeSmith的mysql驱动是没法获取表和列的描述。因此咱们须要从新修改MySQLSchemaProvide。步骤以下:sql

  1. 按照路径,打开项目。
  2. 注意须要从新引入dll。
  3. 打开mysql客户端程序,先查看表结构和列结构.
  4. 打开项目,修改代码,关键代码以下:
  5. 上面是增长了表的描述列,方法的下面是表的描述,原有内容为:
    if (schemaObject is TableSchema)
                {
                    TableSchema tableSchema = schemaObject as TableSchema;
                    string commandText = string.Format(@"SHOW CREATE TABLE `{0}`.`{1}`", tableSchema.Database.Name, tableSchema.Name);
    
                    using (DbConnection connection = CreateConnection(connectionString))
                    {
                        connection.Open();
    
                        DbCommand command = connection.CreateCommand();
                        command.CommandText = commandText;
                        command.Connection = connection;
    
                        using (IDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection))
                        {
                            while (reader.Read())
                            {
                                string createtable = reader.GetString(1);
                                extendedProperties.Add(new ExtendedProperty("CS_CreateTableScript", createtable, DbType.String));
                            }
    
                            if (!reader.IsClosed)
                                reader.Close();
                        }
    
                        if (connection.State != ConnectionState.Closed)
                            connection.Close();
                    }
                }
    
  6. 将上面的sql语句修改成Select TABLE_NAME,TABLE_COMMENT From information_schema.`TABLES` where TABLE_SCHEMA='{0}' and TABLE_NAME='{1}'。而且将extendedProperties.Add(new ExtendedProperty("CS_CreateTableScript", createtable, DbType.String));修改成 extendedProperties.Add(new ExtendedProperty("CS_Description", createtable, DbType.String));
  7. 从新编译后,将编译后的dll组件替换codeSmith7里面的dll。路径如图
  8. 最终效果图

若须要完成的dll,能够留下邮件地址。抽空能够发送完成的dll给你们。ide

相关文章
相关标签/搜索