zoukankan      html  css  js  c++  java
  • CodeSmith7连接Mysql

    由于CodeSmith连接MySql的dll有点小Bug,无法获取表和列的描述信息,所以,需要重新修改驱动程序。

    如上图所示,CodeSmith的mysql驱动是无法获取表和列的描述。所以我们需要重新修改MySQLSchemaProvide。步骤如下:

    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给大家。

  • 相关阅读:
    C#委托及事件 详解(讲得比较透彻)
    浅谈前端常用脚手架cli工具及案例
    C++实现二分法详解
    重新整理 .net core 实践篇————重定向攻击[三十九]
    动态规划_备忘录法_矩阵链乘问题
    完了,又火一个项目
    DOM常用的属性和方法
    一些胡乱的吐槽
    Mac安装compass失败的原因
    css动画animation-keyframes
  • 原文地址:https://www.cnblogs.com/elqy/p/4193024.html
Copyright © 2011-2022 走看看