Browse Source

Update logic delete bug

pull/10/head
sunkaixuna 3 years ago
parent
commit
b4333c2fe2
  1. 1
      Src/Asp.NetCore2/SqlSeverTest/SqlSeverTest/Demo/Demo2_Updateable.cs
  2. 11
      Src/Asp.NetCore2/SqlSeverTest/SqlSeverTest/Demo/Demo4_Deleteable.cs
  3. 4
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/DeleteProvider/LogicDeleteProvider.cs
  4. 9
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs

1
Src/Asp.NetCore2/SqlSeverTest/SqlSeverTest/Demo/Demo2_Updateable.cs

@ -100,6 +100,7 @@ namespace OrmTest
//Where Sql
//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 ####");
}

11
Src/Asp.NetCore2/SqlSeverTest/SqlSeverTest/Demo/Demo4_Deleteable.cs

@ -41,8 +41,19 @@ namespace OrmTest
//by expression
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 ####");
}
public class LogicDeleteTezt
{
public string Name { get; set; }
[SugarColumn(IsPrimaryKey =true)]
public int Id { get; set; }
public bool IsDeleted { get; set; }
}
}
}

4
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/DeleteProvider/LogicDeleteProvider.cs

@ -17,11 +17,11 @@ namespace SqlSugar
List<SugarParameter> pars;
string where;
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)
updateable.UpdateBuilder.Parameters.AddRange(pars);
Convert(updateable as UpdateableProvider<T>);
var result = updateable.Where(where, new { IsDeleted = true }).ExecuteCommand();
var result = updateable.Where(where).ExecuteCommand();
return result;
}
public async Task<int> ExecuteCommandAsync(string LogicFieldName = null)

9
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs

@ -299,7 +299,14 @@ namespace SqlSugar
{
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();
AppendSets();
return this;

Loading…
Cancel
Save