mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-06-28 13:34:32 +08:00
Add 1 field to batch update
This commit is contained in:
parent
19c1f8ab7c
commit
682d449dd3
14
Src/Asp.Net/SqlSugar/Abstract/SqlBuilderProvider/Entities.cs
Normal file
14
Src/Asp.Net/SqlSugar/Abstract/SqlBuilderProvider/Entities.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace SqlSugar
|
||||||
|
{
|
||||||
|
internal class ReSetValueBySqlExpListModel
|
||||||
|
{
|
||||||
|
public string DbColumnName { get; set; }
|
||||||
|
public string Sql { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -36,7 +36,8 @@ namespace SqlSugar
|
|||||||
public List<string> UpdateColumns { get; set; }
|
public List<string> UpdateColumns { get; set; }
|
||||||
public List<JoinQueryInfo> JoinInfos { get; set; }
|
public List<JoinQueryInfo> JoinInfos { get; set; }
|
||||||
public string ShortName { get; set; }
|
public string ShortName { get; set; }
|
||||||
|
internal Dictionary<string, ReSetValueBySqlExpListModel> ReSetValueBySqlExpList { get; set; }
|
||||||
|
public virtual string ReSetValueBySqlExpListType { get; set; }
|
||||||
public virtual string SqlTemplate
|
public virtual string SqlTemplate
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@ -423,6 +424,10 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
return LambdaExpressions.DbMehtods.GetDate();
|
return LambdaExpressions.DbMehtods.GetDate();
|
||||||
}
|
}
|
||||||
|
else if (this.ReSetValueBySqlExpListType!=null&&this.ReSetValueBySqlExpList != null && this.ReSetValueBySqlExpList.ContainsKey(columnInfo.PropertyName))
|
||||||
|
{
|
||||||
|
return this.ReSetValueBySqlExpList[columnInfo.PropertyName].Sql;
|
||||||
|
}
|
||||||
else if (columnInfo.UpdateSql.HasValue())
|
else if (columnInfo.UpdateSql.HasValue())
|
||||||
{
|
{
|
||||||
return columnInfo.UpdateSql;
|
return columnInfo.UpdateSql;
|
||||||
|
@ -360,6 +360,36 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IUpdateable<T> PublicSetColumns(Expression<Func<T, object>> filedNameExpression, Expression<Func<T, object>> ValueExpExpression)
|
||||||
|
{
|
||||||
|
if (UpdateParameterIsNull == true)
|
||||||
|
{
|
||||||
|
return SetColumns(filedNameExpression, ValueExpExpression);
|
||||||
|
}
|
||||||
|
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()
|
||||||
|
{
|
||||||
|
Sql = value,
|
||||||
|
DbColumnName =this.SqlBuilder.GetTranslationColumnName(this.EntityInfo.Columns.First(it => it.PropertyName == name).DbColumnName)
|
||||||
|
}); ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Update by object
|
#region Update by object
|
||||||
|
@ -100,6 +100,7 @@ namespace SqlSugar
|
|||||||
IUpdateable<T> EnableDiffLogEvent(object businessData = null);
|
IUpdateable<T> EnableDiffLogEvent(object businessData = null);
|
||||||
IUpdateable<T> EnableDiffLogEventIF(bool isEnableDiffLog,object businessData = null);
|
IUpdateable<T> EnableDiffLogEventIF(bool isEnableDiffLog,object businessData = null);
|
||||||
IUpdateable<T> ReSetValue(Action<T> setValueExpression);
|
IUpdateable<T> ReSetValue(Action<T> setValueExpression);
|
||||||
|
IUpdateable<T> PublicSetColumns (Expression<Func<T,object>> filedNameExpression, Expression<Func<T, object>> ValueExpExpression);
|
||||||
IUpdateable<T> RemoveDataCache();
|
IUpdateable<T> RemoveDataCache();
|
||||||
IUpdateable<T> RemoveDataCache(string likeString);
|
IUpdateable<T> RemoveDataCache(string likeString);
|
||||||
IUpdateable<T> CallEntityMethod(Expression<Action<T>> method);
|
IUpdateable<T> CallEntityMethod(Expression<Action<T>> method);
|
||||||
|
@ -68,9 +68,26 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
batchUpdateSql.AppendFormat(SqlTemplateJoin, updateTable, whereString);
|
batchUpdateSql.AppendFormat(SqlTemplateJoin, updateTable, whereString);
|
||||||
}
|
}
|
||||||
|
batchUpdateSql = GetBatchUpdateSql(batchUpdateSql);
|
||||||
return batchUpdateSql.ToString();
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
private object GetValue(DbColumnInfo it)
|
private object GetValue(DbColumnInfo it)
|
||||||
{
|
{
|
||||||
if (it.SqlParameterDbType!=null&&it.SqlParameterDbType.Equals(System.Data.DbType.AnsiString))
|
if (it.SqlParameterDbType!=null&&it.SqlParameterDbType.Equals(System.Data.DbType.AnsiString))
|
||||||
|
@ -140,6 +140,7 @@
|
|||||||
<Compile Include="Abstract\QueryableProvider\NavigatManager.cs" />
|
<Compile Include="Abstract\QueryableProvider\NavigatManager.cs" />
|
||||||
<Compile Include="Abstract\SaveableProvider\StorageableMethodInfo.cs" />
|
<Compile Include="Abstract\SaveableProvider\StorageableMethodInfo.cs" />
|
||||||
<Compile Include="Abstract\SaveableProvider\StorageableDataTable.cs" />
|
<Compile Include="Abstract\SaveableProvider\StorageableDataTable.cs" />
|
||||||
|
<Compile Include="Abstract\SqlBuilderProvider\Entities.cs" />
|
||||||
<Compile Include="Abstract\SqlBuilderProvider\SqlBuilderProvider_Condition.cs" />
|
<Compile Include="Abstract\SqlBuilderProvider\SqlBuilderProvider_Condition.cs" />
|
||||||
<Compile Include="Abstract\SugarProvider\SqlSugarCoreProvider.cs" />
|
<Compile Include="Abstract\SugarProvider\SqlSugarCoreProvider.cs" />
|
||||||
<Compile Include="Abstract\DeleteProvider\DeleteMethodInfo.cs" />
|
<Compile Include="Abstract\DeleteProvider\DeleteMethodInfo.cs" />
|
||||||
|
Loading…
Reference in New Issue
Block a user