From 006c17e15b2ab441be1f24188a4dda054c6d1cbd Mon Sep 17 00:00:00 2001 From: 2881099 <2881099@qq.com> Date: Thu, 14 Jul 2022 15:55:57 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E4=BF=AE=E5=A4=8D=20MySql=20DbFirst=20?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E5=AD=97=E6=AE=B5=E6=9C=AA=E6=8E=92=E5=BA=8F?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Providers/FreeSql.Provider.MySql/MySqlDbFirst.cs | 8 +++++--- Providers/FreeSql.Provider.Odbc/MySql/OdbcMySqlDbFirst.cs | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Providers/FreeSql.Provider.MySql/MySqlDbFirst.cs b/Providers/FreeSql.Provider.MySql/MySqlDbFirst.cs index 93212a82..47dd0d82 100644 --- a/Providers/FreeSql.Provider.MySql/MySqlDbFirst.cs +++ b/Providers/FreeSql.Provider.MySql/MySqlDbFirst.cs @@ -278,14 +278,14 @@ a.column_type, case when a.is_nullable = 'YES' then 1 else 0 end 'is_nullable', case when locate('auto_increment', a.extra) > 0 then 1 else 0 end 'is_identity', a.column_comment 'comment', -a.column_default 'default_value' +a.column_default 'default_value', +a.ordinal_position from information_schema.columns a where {(ignoreCase ? "lower(a.table_schema)" : "a.table_schema")} in ({databaseIn}) and {loc8} "; ds = _orm.Ado.ExecuteArray(CommandType.Text, sql); if (ds == null) return loc1; - var position = 0; foreach (var row in ds) { string table_id = string.Concat(row[0]); @@ -299,6 +299,8 @@ where {(ignoreCase ? "lower(a.table_schema)" : "a.table_schema")} in ({databaseI bool is_identity = string.Concat(row[6]) == "1"; string comment = string.Concat(row[7]); string defaultValue = string.Concat(row[8]); + var position = int.Parse(string.Concat(row[9])); + if (max_length == 0) max_length = -1; if (database.Length == 1) { @@ -316,7 +318,7 @@ where {(ignoreCase ? "lower(a.table_schema)" : "a.table_schema")} in ({databaseI Table = loc2[table_id], Comment = comment, DefaultValue = defaultValue, - Position = ++position + Position = position }); loc3[table_id][column].DbType = this.GetDbType(loc3[table_id][column]); loc3[table_id][column].CsType = this.GetCsTypeInfo(loc3[table_id][column]); diff --git a/Providers/FreeSql.Provider.Odbc/MySql/OdbcMySqlDbFirst.cs b/Providers/FreeSql.Provider.Odbc/MySql/OdbcMySqlDbFirst.cs index ff271ba2..cc3cc2b8 100644 --- a/Providers/FreeSql.Provider.Odbc/MySql/OdbcMySqlDbFirst.cs +++ b/Providers/FreeSql.Provider.Odbc/MySql/OdbcMySqlDbFirst.cs @@ -244,14 +244,14 @@ a.column_type, case when a.is_nullable = 'YES' then 1 else 0 end 'is_nullable', case when locate('auto_increment', a.extra) > 0 then 1 else 0 end 'is_identity', a.column_comment 'comment', -a.column_default 'default_value' +a.column_default 'default_value', +a.ordinal_position from information_schema.columns a where {(ignoreCase ? "lower(a.table_schema)" : "a.table_schema")} in ({databaseIn}) and {loc8} "; ds = _orm.Ado.ExecuteArray(CommandType.Text, sql); if (ds == null) return loc1; - var position = 0; foreach (var row in ds) { string table_id = string.Concat(row[0]); @@ -265,6 +265,8 @@ where {(ignoreCase ? "lower(a.table_schema)" : "a.table_schema")} in ({databaseI bool is_identity = string.Concat(row[6]) == "1"; string comment = string.Concat(row[7]); string defaultValue = string.Concat(row[8]); + var position = int.Parse(string.Concat(row[9])); + if (max_length == 0) max_length = -1; if (database.Length == 1) { @@ -282,7 +284,7 @@ where {(ignoreCase ? "lower(a.table_schema)" : "a.table_schema")} in ({databaseI Table = loc2[table_id], Comment = comment, DefaultValue = defaultValue, - Position = ++position + Position = position }); loc3[table_id][column].DbType = this.GetDbType(loc3[table_id][column]); loc3[table_id][column].CsType = this.GetCsTypeInfo(loc3[table_id][column]);