Browse Source

Synchronization code

pull/33/head
sunkaixuan 2 years ago
parent
commit
335f9bd690
  1. 6
      Src/Asp.NetCore2/SqlSugar/Abstract/SqlBuilderProvider/Entities.cs
  2. 7
      Src/Asp.NetCore2/SqlSugar/Abstract/SqlBuilderProvider/UpdateBuilder.cs
  3. 30
      Src/Asp.NetCore2/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs
  4. 1
      Src/Asp.NetCore2/SqlSugar/Interface/IUpdateable.cs
  5. 7
      Src/Asp.NetCore2/SqlSugar/Realization/Kdbndp/SqlBuilder/KdbndpUpdateBuilder.cs
  6. 7
      Src/Asp.NetCore2/SqlSugar/Realization/MySql/SqlBuilder/MySqlUpdateBuilder.cs
  7. 9
      Src/Asp.NetCore2/SqlSugar/Realization/PostgreSQL/SqlBuilder/PostgreSQLUpdateBuilder.cs
  8. 9
      Src/Asp.NetCore2/SqlSugar/Realization/SqlServer/SqlBuilder/SqlServerUpdateBuilder.cs

6
Src/Asp.NetCore2/SqlSugar/Abstract/SqlBuilderProvider/Entities.cs

@ -10,5 +10,11 @@ namespace SqlSugar
{
public string DbColumnName { get; set; }
public string Sql { get; set; }
public ReSetValueBySqlExpListModelType? Type { get; set; }
}
internal enum ReSetValueBySqlExpListModelType
{
Default,
List
}
}

7
Src/Asp.NetCore2/SqlSugar/Abstract/SqlBuilderProvider/UpdateBuilder.cs

@ -425,9 +425,16 @@ namespace SqlSugar
return LambdaExpressions.DbMehtods.GetDate();
}
else if (IsListSetExp(columnInfo)|| IsSingleSetExp(columnInfo))
{
if (this.ReSetValueBySqlExpList[columnInfo.PropertyName].Type == ReSetValueBySqlExpListModelType.List)
{
return columnInfo.DbColumnName+this.ReSetValueBySqlExpList[columnInfo.PropertyName].Sql+name;
}
else
{
return this.ReSetValueBySqlExpList[columnInfo.PropertyName].Sql;
}
}
else if (columnInfo.UpdateSql.HasValue())
{
return columnInfo.UpdateSql;

30
Src/Asp.NetCore2/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs

@ -360,6 +360,36 @@ namespace SqlSugar
}
return this;
}
public IUpdateable<T> PublicSetColumns(Expression<Func<T, object>> filedNameExpression, string computationalSymbol)
{
if (UpdateParameterIsNull == true)
{
Check.Exception(UpdateParameterIsNull == true, ErrorMessage.GetThrowMessage("The PublicSetColumns(exp,string) overload can only be used to update entity objects: db.Updateable(object)", "PublicSetColumns(exp,string)重载只能用在实体对象更新:db.Updateable(对象),请区分表达式更新和实体对象更不同用法 "));
}
else
{
var name = ExpressionTool.GetMemberName(filedNameExpression);
if (name == null)
{
Check.ExceptionEasy(filedNameExpression + " format error ", filedNameExpression + "参数格式错误");
}
//var value = this.UpdateBuilder.GetExpressionValue(ValueExpExpression, ResolveExpressType.WhereSingle).GetResultString();
if (this.UpdateBuilder.ReSetValueBySqlExpList == null)
{
this.UpdateBuilder.ReSetValueBySqlExpList = new Dictionary<string, ReSetValueBySqlExpListModel>();
}
if (!this.UpdateBuilder.ReSetValueBySqlExpList.ContainsKey(name))
{
this.UpdateBuilder.ReSetValueBySqlExpList.Add(name, new ReSetValueBySqlExpListModel()
{
Type= ReSetValueBySqlExpListModelType.List,
Sql = computationalSymbol,
DbColumnName = this.SqlBuilder.GetTranslationColumnName(this.EntityInfo.Columns.First(it => it.PropertyName == name).DbColumnName)
});
}
}
return this;
}
public IUpdateable<T> PublicSetColumns(Expression<Func<T, object>> filedNameExpression, Expression<Func<T, object>> ValueExpExpression)
{

1
Src/Asp.NetCore2/SqlSugar/Interface/IUpdateable.cs

@ -100,6 +100,7 @@ namespace SqlSugar
IUpdateable<T> EnableDiffLogEvent(object businessData = null);
IUpdateable<T> EnableDiffLogEventIF(bool isEnableDiffLog,object businessData = null);
IUpdateable<T> ReSetValue(Action<T> setValueExpression);
IUpdateable<T> PublicSetColumns(Expression<Func<T, object>> filedNameExpression,string computationalSymbol);
IUpdateable<T> PublicSetColumns (Expression<Func<T,object>> filedNameExpression, Expression<Func<T, object>> ValueExpExpression);
IUpdateable<T> RemoveDataCache();
IUpdateable<T> RemoveDataCache(string likeString);

7
Src/Asp.NetCore2/SqlSugar/Realization/Kdbndp/SqlBuilder/KdbndpUpdateBuilder.cs

@ -190,7 +190,14 @@ namespace SqlSugar
foreach (var item in ReSetValueBySqlExpList)
{
var dbColumnName = item.Value.DbColumnName;
if (item.Value.Type == ReSetValueBySqlExpListModelType.List)
{
result = result.Replace($"{dbColumnName}=T.{dbColumnName}", $"{dbColumnName}={GetTableNameString}.{dbColumnName}{item.Value.Sql}T.{dbColumnName}");
}
else
{
result = result.Replace($"{dbColumnName}=T.{dbColumnName}", $"{dbColumnName}={item.Value.Sql.Replace(dbColumnName, $"{Builder.GetTranslationColumnName(this.TableName)}.{dbColumnName}")}");
}
batchUpdateSql = new StringBuilder(result);
}
}

7
Src/Asp.NetCore2/SqlSugar/Realization/MySql/SqlBuilder/MySqlUpdateBuilder.cs

@ -109,7 +109,14 @@ namespace SqlSugar
foreach (var item in ReSetValueBySqlExpList)
{
var dbColumnName = item.Value.DbColumnName;
if (item.Value.Type == ReSetValueBySqlExpListModelType.List)
{
result = result.Replace($"T.{dbColumnName}", "S." + dbColumnName+item.Value.Sql+ "T." + dbColumnName);
}
else
{
result = result.Replace($"T.{dbColumnName}", item.Value.Sql.Replace(dbColumnName, "S." + dbColumnName));
}
batchUpdateSql = new StringBuilder(result);
}
}

9
Src/Asp.NetCore2/SqlSugar/Realization/PostgreSQL/SqlBuilder/PostgreSQLUpdateBuilder.cs

@ -210,7 +210,14 @@ namespace SqlSugar
foreach (var item in ReSetValueBySqlExpList)
{
var dbColumnName = item.Value.DbColumnName;
result = result.Replace($"{dbColumnName}=T.{dbColumnName}", $"{dbColumnName}={item.Value.Sql.Replace(dbColumnName,$"{Builder.GetTranslationColumnName( this.TableName)}.{dbColumnName}")}");
if (item.Value.Type == ReSetValueBySqlExpListModelType.List)
{
result = result.Replace($"{dbColumnName}=T.{dbColumnName}", $"{dbColumnName}={GetTableNameString}.{dbColumnName}{item.Value.Sql}T.{dbColumnName}");
}
else
{
result = result.Replace($"{dbColumnName}=T.{dbColumnName}", $"{dbColumnName}={item.Value.Sql.Replace(dbColumnName, $"{Builder.GetTranslationColumnName(this.TableName)}.{dbColumnName}")}");
}
batchUpdateSql = new StringBuilder(result);
}
}

9
Src/Asp.NetCore2/SqlSugar/Realization/SqlServer/SqlBuilder/SqlServerUpdateBuilder.cs

@ -80,7 +80,14 @@ namespace SqlSugar
foreach (var item in ReSetValueBySqlExpList)
{
var dbColumnName = item.Value.DbColumnName;
result = result.Replace($"T.{dbColumnName}", item.Value.Sql.Replace(dbColumnName,"S."+ dbColumnName));
if (item.Value.Type==ReSetValueBySqlExpListModelType.List)
{
result = result.Replace($"T.{dbColumnName}", $" T.{dbColumnName}{item.Value.Sql}S.{dbColumnName}");
}
else
{
result = result.Replace($"T.{dbColumnName}", item.Value.Sql.Replace(dbColumnName, "S." + dbColumnName));
}
batchUpdateSql = new StringBuilder(result);
}
}

Loading…
Cancel
Save