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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM