mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-23 22:11:36 +08:00
Update logic delete bug
This commit is contained in:
parent
3c12bbee84
commit
b4333c2fe2
@ -100,6 +100,7 @@ namespace OrmTest
|
|||||||
//Where Sql
|
//Where Sql
|
||||||
//db.Updateable(updateObj).Where("id=@x", new { x = "1" }).ExecuteCommand();
|
//db.Updateable(updateObj).Where("id=@x", new { x = "1" }).ExecuteCommand();
|
||||||
|
|
||||||
|
db.Updateable<Order>().SetColumns("name", 1).Where(it => it.Id == 1).ExecuteCommand();
|
||||||
Console.WriteLine("#### Updateable End ####");
|
Console.WriteLine("#### Updateable End ####");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,8 +41,19 @@ namespace OrmTest
|
|||||||
//by expression
|
//by expression
|
||||||
db.Deleteable<Order>().Where(it => it.Id == 11111).ExecuteCommand();
|
db.Deleteable<Order>().Where(it => it.Id == 11111).ExecuteCommand();
|
||||||
|
|
||||||
|
//logic delete
|
||||||
|
db.CodeFirst.InitTables<LogicDeleteTezt>();
|
||||||
|
db.Deleteable<LogicDeleteTezt>().Where(it=>it.Name=="a").IsLogic().ExecuteCommand();
|
||||||
Console.WriteLine("#### Deleteable End ####");
|
Console.WriteLine("#### Deleteable End ####");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class LogicDeleteTezt
|
||||||
|
{
|
||||||
|
public string Name { get; set; }
|
||||||
|
[SugarColumn(IsPrimaryKey =true)]
|
||||||
|
public int Id { get; set; }
|
||||||
|
public bool IsDeleted { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,11 +17,11 @@ namespace SqlSugar
|
|||||||
List<SugarParameter> pars;
|
List<SugarParameter> pars;
|
||||||
string where;
|
string where;
|
||||||
LogicFieldName = _ExecuteCommand(LogicFieldName, out db, out where, out pars);
|
LogicFieldName = _ExecuteCommand(LogicFieldName, out db, out where, out pars);
|
||||||
var updateable = db.Updateable<T>().SetColumns(LogicFieldName, "@IsDeleted");
|
var updateable = db.Updateable<T>().SetColumns(LogicFieldName,true);
|
||||||
if (pars != null)
|
if (pars != null)
|
||||||
updateable.UpdateBuilder.Parameters.AddRange(pars);
|
updateable.UpdateBuilder.Parameters.AddRange(pars);
|
||||||
Convert(updateable as UpdateableProvider<T>);
|
Convert(updateable as UpdateableProvider<T>);
|
||||||
var result = updateable.Where(where, new { IsDeleted = true }).ExecuteCommand();
|
var result = updateable.Where(where).ExecuteCommand();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
public async Task<int> ExecuteCommandAsync(string LogicFieldName = null)
|
public async Task<int> ExecuteCommandAsync(string LogicFieldName = null)
|
||||||
|
@ -299,7 +299,14 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
fieldName = columnInfo.DbColumnName;
|
fieldName = columnInfo.DbColumnName;
|
||||||
}
|
}
|
||||||
UpdateBuilder.SetValues.Add(new KeyValuePair<string, string>(fieldName, fieldValue+""));
|
var parameterName =this.SqlBuilder.SqlParameterKeyWord+ "Const" + this.UpdateBuilder.LambdaExpressions.ParameterIndex;
|
||||||
|
this.UpdateBuilder.LambdaExpressions.ParameterIndex = this.UpdateBuilder.LambdaExpressions.ParameterIndex+1;
|
||||||
|
if (UpdateBuilder.Parameters == null)
|
||||||
|
{
|
||||||
|
UpdateBuilder.Parameters = new List<SugarParameter>();
|
||||||
|
}
|
||||||
|
UpdateBuilder.Parameters.Add(new SugarParameter(parameterName, fieldValue));
|
||||||
|
UpdateBuilder.SetValues.Add(new KeyValuePair<string, string>(SqlBuilder.GetTranslationColumnName(fieldName), $"{SqlBuilder.GetTranslationColumnName(fieldName)}={parameterName}"));
|
||||||
this.UpdateBuilder.DbColumnInfoList = this.UpdateBuilder.DbColumnInfoList.Where(it => (UpdateParameterIsNull == false && IsPrimaryKey(it)) || UpdateBuilder.SetValues.Any(v => SqlBuilder.GetNoTranslationColumnName(v.Key).Equals(it.DbColumnName, StringComparison.CurrentCultureIgnoreCase) || SqlBuilder.GetNoTranslationColumnName(v.Key).Equals(it.PropertyName, StringComparison.CurrentCultureIgnoreCase)) || it.IsPrimarykey == true).ToList();
|
this.UpdateBuilder.DbColumnInfoList = this.UpdateBuilder.DbColumnInfoList.Where(it => (UpdateParameterIsNull == false && IsPrimaryKey(it)) || UpdateBuilder.SetValues.Any(v => SqlBuilder.GetNoTranslationColumnName(v.Key).Equals(it.DbColumnName, StringComparison.CurrentCultureIgnoreCase) || SqlBuilder.GetNoTranslationColumnName(v.Key).Equals(it.PropertyName, StringComparison.CurrentCultureIgnoreCase)) || it.IsPrimarykey == true).ToList();
|
||||||
AppendSets();
|
AppendSets();
|
||||||
return this;
|
return this;
|
||||||
|
Loading…
Reference in New Issue
Block a user