diff --git a/Src/Asp.NetCore2/SqlSugar/Abstract/ExecuteNavProvider/UpdateNavOneToMany.cs b/Src/Asp.NetCore2/SqlSugar/Abstract/ExecuteNavProvider/UpdateNavOneToMany.cs index f35e56dda..4ed6300b1 100644 --- a/Src/Asp.NetCore2/SqlSugar/Abstract/ExecuteNavProvider/UpdateNavOneToMany.cs +++ b/Src/Asp.NetCore2/SqlSugar/Abstract/ExecuteNavProvider/UpdateNavOneToMany.cs @@ -46,9 +46,34 @@ namespace SqlSugar if (NotAny(name)) { DeleteMany(thisEntity, ids, thisFkColumn.DbColumnName); - this._Context.Deleteable() - .AS(thisEntity.DbTableName) - .In(thisFkColumn.DbColumnName, ids.Distinct().ToList()).ExecuteCommand(); + if (this._Options?.OneToManyEnableLogicDelete == true) + { + var locgicColumn = thisEntity.Columns.FirstOrDefault(it => it.PropertyName.EqualCase("IsDeleted") || it.PropertyName.EqualCase("IsDelete")); + Check.ExceptionEasy( + locgicColumn==null, + thisEntity.EntityName + "Logical deletion requires the entity to have the IsDeleted property", + thisEntity.EntityName+"假删除需要实体有IsDeleted属性"); + List conditionalModels = new List(); + conditionalModels.Add(new ConditionalModel() + { + FieldName = thisFkColumn.DbColumnName, + FieldValue = string.Join(",", ids.Distinct()), + ConditionalType = ConditionalType.In, + CSharpTypeName = thisFkColumn.PropertyName + }); + var sqlObj = _Context.Queryable().SqlBuilder.ConditionalModelToSql(conditionalModels); + this._Context.Updateable() + .AS(thisEntity.DbTableName) + .Where(sqlObj.Key, sqlObj.Value) + .SetColumns(locgicColumn.DbColumnName, true) + .ExecuteCommand(); + } + else + { + this._Context.Deleteable() + .AS(thisEntity.DbTableName) + .In(thisFkColumn.DbColumnName, ids.Distinct().ToList()).ExecuteCommand(); + } _NavigateType = NavigateType.OneToMany; InsertDatas(children, thisPkColumn); } diff --git a/Src/Asp.NetCore2/SqlSugar/Entities/DeleteNavOptions.cs b/Src/Asp.NetCore2/SqlSugar/Entities/DeleteNavOptions.cs index 42aba04ab..2df31e346 100644 --- a/Src/Asp.NetCore2/SqlSugar/Entities/DeleteNavOptions.cs +++ b/Src/Asp.NetCore2/SqlSugar/Entities/DeleteNavOptions.cs @@ -44,6 +44,7 @@ namespace SqlSugar public bool ManyToManyIsUpdateA { get; set; } public bool ManyToManyIsUpdateB { get; set; } public bool OneToManyDeleteAll { get; set; } + public bool OneToManyEnableLogicDelete { get; set; } public Expression RootFunc { get; set; } public Expression CurrentFunc { get; set; } }