mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-23 21:56:03 +08:00
Update db.Updateable(objs).ReSetValue
This commit is contained in:
parent
35b7926944
commit
b44a496c8b
@ -54,6 +54,8 @@ namespace OrmTest
|
||||
var result5 = db.Updateable(updateObj).WhereColumns(it => new { it.Id }).ExecuteCommand();//update single by id
|
||||
var result6 = db.Updateable(updateObjs).WhereColumns(it => new { it.Id }).ExecuteCommand();//update List<Class> by id
|
||||
|
||||
//Re set value
|
||||
var result66 = db.Updateable(new List<Order> { updateObj }).ReSetValue(it => it.Id = 112).IgnoreColumns(it => new { it.CreateTime, it.Price }).ExecuteCommand();
|
||||
|
||||
|
||||
|
||||
|
@ -23,9 +23,9 @@ namespace OrmTest
|
||||
Db.Updateable<UnitBoolTest>().SetColumns(it => it.BoolValue == x.BoolValue).Where(it => it.Id == 1).ExecuteCommand();
|
||||
Db.Updateable<UnitBoolTest>().SetColumns(it => new UnitBoolTest() { BoolValue = !x.BoolValue }).Where(it => it.Id == 1).ExecuteCommand();
|
||||
Db.Updateable<UnitBoolTest>().SetColumns(it => it.BoolValue == !x.BoolValue).Where(it => it.Id == 1).ExecuteCommand();
|
||||
Db.Updateable<UnitBoolTest>(x).ReSetValue(it => it.BoolValue == it.BoolValue).ExecuteCommand();
|
||||
Db.Updateable<UnitBoolTest>(x).ReSetValue(it => it.BoolValue == true).ExecuteCommand();
|
||||
Db.Updateable<UnitBoolTest>(x).ReSetValue(it => it.BoolValue == !it.BoolValue).ExecuteCommand();
|
||||
Db.Updateable<UnitBoolTest>(x).ReSetValue(it => it.BoolValue = it.BoolValue).ExecuteCommand();
|
||||
Db.Updateable<UnitBoolTest>(x).ReSetValue(it => it.BoolValue = true).ExecuteCommand();
|
||||
Db.Updateable<UnitBoolTest>(x).ReSetValue(it => it.BoolValue = !it.BoolValue).ExecuteCommand();
|
||||
Db.Updateable<UnitBoolTest>(x).UpdateColumns(it => new { it.BoolValue }).ExecuteCommand();
|
||||
|
||||
|
||||
|
@ -181,19 +181,20 @@ namespace SqlSugar
|
||||
}
|
||||
|
||||
|
||||
public IUpdateable<T> ReSetValue(Expression<Func<T, bool>> setValueExpression)
|
||||
public IUpdateable<T> ReSetValue(Action<T> setValueExpression)
|
||||
{
|
||||
Check.Exception(!IsSingle, "Batch operation not supported ReSetValue");
|
||||
var expResult = UpdateBuilder.GetExpressionValue(setValueExpression, ResolveExpressType.WhereSingle);
|
||||
var resultString = Regex.Match(expResult.GetResultString(), @"\((.+)\)").Groups[1].Value;
|
||||
LambdaExpression lambda = setValueExpression as LambdaExpression;
|
||||
var expression = lambda.Body;
|
||||
Check.Exception(!(expression is BinaryExpression), "Expression format error");
|
||||
Check.Exception((expression as BinaryExpression).NodeType != ExpressionType.Equal, "Expression format error");
|
||||
var leftExpression = (expression as BinaryExpression).Left;
|
||||
Check.Exception(!(leftExpression is MemberExpression), "Expression format error");
|
||||
var leftResultString = UpdateBuilder.GetExpressionValue(leftExpression, ResolveExpressType.FieldSingle).GetString();
|
||||
UpdateBuilder.SetValues.Add(new KeyValuePair<string, string>(leftResultString, resultString));
|
||||
ThrowUpdateByExpression();
|
||||
if (this.UpdateObjs.HasValue())
|
||||
{
|
||||
var oldColumns = this.UpdateBuilder.DbColumnInfoList.Select(it => it.PropertyName).ToList();
|
||||
foreach (var item in UpdateObjs)
|
||||
{
|
||||
setValueExpression(item);
|
||||
}
|
||||
this.UpdateBuilder.DbColumnInfoList = new List<DbColumnInfo>();
|
||||
Init();
|
||||
this.UpdateBuilder.DbColumnInfoList = this.UpdateBuilder.DbColumnInfoList.Where(it => oldColumns.Contains(it.PropertyName)).ToList();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -86,7 +86,7 @@ namespace SqlSugar
|
||||
|
||||
IUpdateable<T> IsEnableUpdateVersionValidation();
|
||||
IUpdateable<T> EnableDiffLogEvent(object businessData = null);
|
||||
IUpdateable<T> ReSetValue(Expression<Func<T, bool>> setValueExpression);
|
||||
IUpdateable<T> ReSetValue(Action<T> setValueExpression);
|
||||
IUpdateable<T> RemoveDataCache();
|
||||
IUpdateable<T> RemoveDataCache(string likeString);
|
||||
IUpdateable<T> CallEntityMethod(Expression<Action<T>> method);
|
||||
|
Loading…
Reference in New Issue
Block a user