PublicExtendedproperty[] Getextendedproperties (stringconnectionString, Schemaobjectbase schemaobject) {List<ExtendedProperty> extendedproperties =NewList<extendedproperty>(); if(Schemaobject isColumnschema) {Columnschema Columnschema= Schemaobject asColumnschema; stringCommandText =string. Format (@"SELECT EXTRA, Column_default, Column_type,column_comment From INFORMATION_SCHEMA. COLUMNS WHERE table_schema = ' {0} ' and table_name = ' {1} ' and Column_ NAME = ' {2} '", ColumnSchema.Table.Database.Name, ColumnSchema.Table.Name, Colu Mnschema.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 ()) {stringExtra = reader. GetString (0). ToLower (); BOOLColumndefaultisnull = reader. IsDBNull (1); stringColumndefault =""; if(!columndefaultisnull) {Columndefault= Reader. GetString (1). ToUpper (); } stringColumnType = reader. GetString (2). ToUpper (); string columncomment = reader. GetString (3); BOOLIsidentity = (extra. IndexOf ("auto_increment") >-1); Extendedproperties.add (NewExtendedproperty (extendedpropertynames.isidentity, isidentity, Columnschema.datatype)); if(isidentity) {/*MySQL auto_increment doesn ' t work exactly like SQL Server ' s IDENTITY I believe that auto_increment are equivalent to IDENTITY (1, 1) However, auto_i Ncrement behaves differently from the IDENTITY when used with multi-column primary keys. See the MySQL Reference Manual for details. */Extendedproperties.add (NewExtendedproperty (Extendedpropertynames.identityseed,1, Columnschema.datatype)); Extendedproperties.add (NewExtendedproperty (Extendedpropertynames.identityincrement,1, Columnschema.datatype)); } extendedproperties.add (NewExtendedproperty ("Cs_columndefaultisnull", Columndefaultisnull, Dbtype.boolean));//Added for backwards compatibility.Extendedproperties.add (NewExtendedproperty (Extendedpropertynames.defaultvalue, Columndefault, dbtype.string)); Extendedproperties.add (NewExtendedproperty ("Cs_columndefault", Columndefault, dbtype.string));//Added for backwards compatibility.Extendedproperties.add (NewExtendedproperty (Extendedpropertynames.systemtype, ColumnType, dbtype.string)); Extendedproperties.add (NewExtendedproperty ("Cs_columntype", ColumnType, dbtype.string));//Added for backwards compatibility.Extendedproperties.add (NewExtendedproperty ("Cs_columnextra", Extra. ToUpper (), dbtype.string)); Extendedproperties.add ( new Extendedproperty ("Cs_description" , Columncomment, dbtype.string)); } if(!Reader. IsClosed) reader. Close (); } if(Connection. State! =connectionstate.closed) connection. Close (); } } if(Schemaobject isTableschema) {Tableschema Tableschema= Schemaobject asTableschema; stringCommandText =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 ()) {stringCreateTable = reader. GetString (1); //Extendedproperties.add (New Extendedproperty ("Cs_createtablescript", CreateTable, dbtype.string)); Extendedproperties.add (New Extendedproperty ("Ts_description", CreateTable, dbtype.string)); int engineindex = createtable. LastIndexOf ("ENGINE"); int commentindex = createtable. LastIndexOf ("comment="); String tabledescription = reader. GetString (0); if (Commentindex > Engineindex) {tabledescription = Createta ble. Substring (Commentindex + 9). Replace ("'", ""); } extendedproperties.add (New Extendedproperty ("Cs_description" , Tabledescription, dbtype.string)); } if(!Reader. IsClosed) reader. Close (); } if(Connection. State! =connectionstate.closed) connection. Close (); } } returnExtendedproperties.toarray (); }
Solution Codesmith Unable to get MySQL table and column description description comment