From fbbc5fcd82139a55df02e3a507dfaf7fdd2bda5d Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Fri, 6 May 2022 12:55:30 +0800 Subject: [PATCH] Update TableDifference --- .../TableDifferenceProvider.cs | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/Src/Asp.Net/SqlSugar/Abstract/CodeFirstProvider/TableDifferenceProvider.cs b/Src/Asp.Net/SqlSugar/Abstract/CodeFirstProvider/TableDifferenceProvider.cs index bb73b159d..823ab625f 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/CodeFirstProvider/TableDifferenceProvider.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/CodeFirstProvider/TableDifferenceProvider.cs @@ -86,7 +86,7 @@ namespace SqlSugar z.DecimalDigits != y.DecimalDigits ))).Select(it => new DiffColumsInfo() { - Message=GetColumnString(it) + Message= GetUpdateColumnString(it, tableInfo.OldColumnInfos.FirstOrDefault(y => y.DbColumnName.EqualCase(it.DbColumnName))) }).ToList(); return result; } @@ -102,6 +102,40 @@ namespace SqlSugar { return $"{it.DbColumnName} {it.DataType} {it.Length} {it.Scale} default:{it.DefaultValue} description:{it.ColumnDescription} pk:{it.IsPrimarykey} nullable:{it.IsNullable} identity:{it.IsIdentity} "; } + + private static string GetUpdateColumnString(DbColumnInfo it,DbColumnInfo old) + { + var result= $"{it.DbColumnName} changes: "; + if (it.DataType != old.DataType) + { + result += $" [DataType:{old.DataType}->{it.DataType}] "; + } + if (it.Length != old.Length) + { + result += $" [Length:{old.Length}->{it.Length}] "; + } + if (it.Scale != old.Scale) + { + result += $" [Scale:{old.Scale}->{it.Scale}] "; + } + if (it.ColumnDescription != old.ColumnDescription) + { + result += $" [Description:{old.ColumnDescription}->{it.ColumnDescription}] "; + } + if (it.IsPrimarykey != old.IsPrimarykey) + { + result += $" [Pk:{old.IsPrimarykey}->{it.IsPrimarykey}] "; + } + if (it.IsNullable != old.IsNullable) + { + result += $" [Nullable:{old.IsNullable}->{it.IsNullable}] "; + } + if (it.IsIdentity != old.IsIdentity) + { + result += $" [Identity:{old.IsIdentity}->{it.IsIdentity}] "; + } + return result; + } } public class TableDifferenceInfo {