diff --git a/Src/Asp.Net/SqlSugar/Abstract/SqlBuilderProvider/UpdateBuilder.cs b/Src/Asp.Net/SqlSugar/Abstract/SqlBuilderProvider/UpdateBuilder.cs index 4bfa15a02..06f03869a 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/SqlBuilderProvider/UpdateBuilder.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/SqlBuilderProvider/UpdateBuilder.cs @@ -424,7 +424,7 @@ namespace SqlSugar { return LambdaExpressions.DbMehtods.GetDate(); } - else if (this.ReSetValueBySqlExpListType!=null&&this.ReSetValueBySqlExpList != null && this.ReSetValueBySqlExpList.ContainsKey(columnInfo.PropertyName)) + else if (IsListSetExp(columnInfo)|| IsSingleSetExp(columnInfo)) { return this.ReSetValueBySqlExpList[columnInfo.PropertyName].Sql; } @@ -486,6 +486,17 @@ namespace SqlSugar return name + ""; } } + private bool IsSingleSetExp(DbColumnInfo columnInfo) + { + return this.ReSetValueBySqlExpList != null && + this.ReSetValueBySqlExpList.ContainsKey(columnInfo.PropertyName) && + this.IsListUpdate == null&& + DbColumnInfoList.GroupBy(it => it.TableId).Count()==1; + } + private bool IsListSetExp(DbColumnInfo columnInfo) + { + return this.ReSetValueBySqlExpListType != null && this.ReSetValueBySqlExpList != null && this.ReSetValueBySqlExpList.ContainsKey(columnInfo.PropertyName); + } //public virtual string GetDbColumn(DbColumnInfo columnInfo, string name) //{ // if (columnInfo.UpdateServerTime) diff --git a/Src/Asp.Net/SqlSugar/Realization/MySql/SqlBuilder/MySqlUpdateBuilder.cs b/Src/Asp.Net/SqlSugar/Realization/MySql/SqlBuilder/MySqlUpdateBuilder.cs index 8c6b6d0f8..1bca030ed 100644 --- a/Src/Asp.Net/SqlSugar/Realization/MySql/SqlBuilder/MySqlUpdateBuilder.cs +++ b/Src/Asp.Net/SqlSugar/Realization/MySql/SqlBuilder/MySqlUpdateBuilder.cs @@ -97,8 +97,25 @@ namespace SqlSugar batchUpdateSql.Replace("${0}",format); batchUpdateSql.Append(";"); } + batchUpdateSql = GetBatchUpdateSql(batchUpdateSql); return batchUpdateSql.ToString(); } + + private StringBuilder GetBatchUpdateSql(StringBuilder batchUpdateSql) + { + if (ReSetValueBySqlExpListType == null && ReSetValueBySqlExpList != null) + { + var result = batchUpdateSql.ToString(); + foreach (var item in ReSetValueBySqlExpList) + { + var dbColumnName = item.Value.DbColumnName; + result = result.Replace($"T.{dbColumnName}", item.Value.Sql.Replace(dbColumnName, "S." + dbColumnName)); + batchUpdateSql = new StringBuilder(result); + } + } + + return batchUpdateSql; + } int i = 0; public object FormatValue(object value,string name) {