diff --git a/Src/Asp.NetCore2/SqlSugar/Abstract/ExecuteNavProvider/UpdateNavOneToMany.cs b/Src/Asp.NetCore2/SqlSugar/Abstract/ExecuteNavProvider/UpdateNavOneToMany.cs index 4a3052162..94dc66b13 100644 --- a/Src/Asp.NetCore2/SqlSugar/Abstract/ExecuteNavProvider/UpdateNavOneToMany.cs +++ b/Src/Asp.NetCore2/SqlSugar/Abstract/ExecuteNavProvider/UpdateNavOneToMany.cs @@ -10,6 +10,11 @@ namespace SqlSugar { public NavigateType? _NavigateType { get; set; } private void UpdateOneToMany(string name, EntityColumnInfo nav) where TChild : class, new() + { + DeleteInsert(name, nav); + } + + private void DeleteInsert(string name, EntityColumnInfo nav) where TChild : class, new() { List children = new List(); var parentEntity = _ParentEntity; @@ -42,7 +47,7 @@ namespace SqlSugar children.AddRange(childs); } ids.Add(parentValue); - if (_Options?.OneToManyNoDeleteNull == true && childs == null) + if (_Options?.OneToManyNoDeleteNull == true && childs == null) { ids.Remove(parentValue); } @@ -54,9 +59,9 @@ namespace SqlSugar { 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属性"); + 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() { @@ -81,13 +86,14 @@ namespace SqlSugar _NavigateType = NavigateType.OneToMany; InsertDatas(children, thisPkColumn); } - else + else { this._ParentList = children.Cast().ToList(); } _NavigateType = null; SetNewParent(thisEntity, thisPkColumn); } + private static bool ParentIsPk(EntityColumnInfo parentNavigateProperty) { return parentNavigateProperty != null && diff --git a/Src/Asp.NetCore2/SqlSugar/Entities/DeleteNavOptions.cs b/Src/Asp.NetCore2/SqlSugar/Entities/DeleteNavOptions.cs index 32dadefb7..19f9226a9 100644 --- a/Src/Asp.NetCore2/SqlSugar/Entities/DeleteNavOptions.cs +++ b/Src/Asp.NetCore2/SqlSugar/Entities/DeleteNavOptions.cs @@ -51,6 +51,7 @@ namespace SqlSugar public bool OneToManyDeleteAll { get; set; } public bool OneToManyEnableLogicDelete { get; set; } public bool OneToManyNoDeleteNull { get; set; } + public bool OneToManyInsertOrUpdate { get; set; } public Expression RootFunc { get; set; } public Expression CurrentFunc { get; set; } }