Browse Source

Update mysql

pull/32/head
sunkaixuan 2 years ago
parent
commit
d0955ad99f
  1. 13
      Src/Asp.Net/SqlSugar/Abstract/SqlBuilderProvider/UpdateBuilder.cs
  2. 17
      Src/Asp.Net/SqlSugar/Realization/MySql/SqlBuilder/MySqlUpdateBuilder.cs

13
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)

17
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)
{

Loading…
Cancel
Save