From 60cdb3c6def2d24eb59dd670986259af82ece401 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Sat, 9 Jul 2022 12:40:18 +0800 Subject: [PATCH] Delete navicate --- .../ExecuteNavProvider/DeleteNavOneToOne.cs | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/Src/Asp.Net/SqlSugar/Abstract/ExecuteNavProvider/DeleteNavOneToOne.cs b/Src/Asp.Net/SqlSugar/Abstract/ExecuteNavProvider/DeleteNavOneToOne.cs index 6ac67dc67..6ed8868af 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/ExecuteNavProvider/DeleteNavOneToOne.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/ExecuteNavProvider/DeleteNavOneToOne.cs @@ -10,7 +10,27 @@ namespace SqlSugar { private void DeleteOneToOne(string name, EntityColumnInfo nav) where TChild : class, new() { - + var parentEntity = _ParentEntity; + var parentList = _ParentList.Cast().ToList(); + var parentColumn = parentEntity.Columns.FirstOrDefault(it => it.PropertyName == nav.Navigat.Name); + var parentPkColumn = parentEntity.Columns.FirstOrDefault(it => it.IsPrimarykey); + var thisEntity = this._Context.EntityMaintenance.GetEntityInfo(); + EntityColumnInfo thisPkColumn = GetPkColumnByNav(thisEntity, nav); + Check.Exception(thisPkColumn == null, $" Navigate {parentEntity.EntityName} : {name} is error ", $"导航实体 {parentEntity.EntityName} 属性 {name} 配置错误"); + + + if (!_IsDeletedParant) + SetContext(() => this._Context.Deleteable(parentList).ExecuteCommand()); + + + var ids = _ParentList.Select(it => parentColumn.PropertyInfo.GetValue(it)).ToList(); + List childList = this._Context.Queryable().In(thisPkColumn.DbColumnName, ids).ToList(); + + this._ParentList = childList.Cast().ToList(); + this._ParentPkColumn = thisPkColumn; + this._IsDeletedParant = true; + + SetContext(() => this._Context.Deleteable(childList).ExecuteCommand()); } }