Browse Source

ManyToMany logic deleted

pull/40/head
sunkaixuan 1 year ago
parent
commit
7af11e11d5
  1. 27
      Src/Asp.Net/SqlSugar/Abstract/ExecuteNavProvider/UpdateNavManyToMany.cs
  2. 1
      Src/Asp.Net/SqlSugar/Entities/DeleteNavOptions.cs

27
Src/Asp.Net/SqlSugar/Abstract/ExecuteNavProvider/UpdateNavManyToMany.cs

@ -89,7 +89,32 @@ namespace SqlSugar
mappgingTables.Add(keyValuePairs);
}
}
this._Context.Deleteable<object>().AS(mappingEntity.DbTableName).In(mappingA.DbColumnName, ids).ExecuteCommand();
if (this._Options?.ManyToManyEnableLogicDelete == 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<IConditionalModel> conditionalModels = new List<IConditionalModel>();
conditionalModels.Add(new ConditionalModel()
{
FieldName = mappingA.DbColumnName,
FieldValue = string.Join(",", ids.Distinct()),
ConditionalType = ConditionalType.In,
CSharpTypeName = mappingA?.PropertyInfo?.PropertyType?.Name
});
var sqlObj = _Context.Queryable<object>().SqlBuilder.ConditionalModelToSql(conditionalModels);
this._Context.Updateable<object>()
.AS(mappingEntity.DbTableName)
.Where(sqlObj.Key, sqlObj.Value)
.SetColumns(locgicColumn.DbColumnName, true)
.ExecuteCommand();
}
else
{
this._Context.Deleteable<object>().AS(mappingEntity.DbTableName).In(mappingA.DbColumnName, ids).ExecuteCommand();
}
if (HasMappingTemplate(mappingEntity))
{
InertMappingWithTemplate(mappingEntity, mappingA, mappingB, mappgingTables);

1
Src/Asp.Net/SqlSugar/Entities/DeleteNavOptions.cs

@ -44,6 +44,7 @@ namespace SqlSugar
public bool ManyToManyIsUpdateA { get; set; }
public bool ManyToManyIsUpdateB { get; set; }
public object ManyToManySaveMappingTemplate { get; set; }
public bool ManyToManyEnableLogicDelete { get; set; }
public bool OneToManyDeleteAll { get; set; }
public bool OneToManyEnableLogicDelete { get; set; }
public Expression RootFunc { get; set; }

Loading…
Cancel
Save