From 7787828a4c14ca0b989bd3f2b67ca71dc6514a33 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Wed, 21 Sep 2022 20:04:59 +0800 Subject: [PATCH] Synchronization code --- .../ExecuteNavProvider/UpdateNavOneToMany.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Src/Asp.NetCore2/SqlSugar/Abstract/ExecuteNavProvider/UpdateNavOneToMany.cs b/Src/Asp.NetCore2/SqlSugar/Abstract/ExecuteNavProvider/UpdateNavOneToMany.cs index 31e17355c..c072b3a0e 100644 --- a/Src/Asp.NetCore2/SqlSugar/Abstract/ExecuteNavProvider/UpdateNavOneToMany.cs +++ b/Src/Asp.NetCore2/SqlSugar/Abstract/ExecuteNavProvider/UpdateNavOneToMany.cs @@ -24,6 +24,10 @@ namespace SqlSugar { parentPkColumn = parentNavColumn; } + if (ParentIsPk(parentNavigateProperty)) + { + parentPkColumn = this._ParentEntity.Columns.FirstOrDefault(it => it.IsPrimarykey); + } var ids = new List(); foreach (var item in parentList) { @@ -48,7 +52,13 @@ namespace SqlSugar _NavigateType = null; SetNewParent(thisEntity, thisPkColumn); } - + private static bool ParentIsPk(EntityColumnInfo parentNavigateProperty) + { + return parentNavigateProperty != null && + parentNavigateProperty.Navigat != null && + parentNavigateProperty.Navigat.NavigatType == NavigateType.OneToMany && + parentNavigateProperty.Navigat.Name2 == null; + } private void DeleteMany(EntityInfo thisEntity, List ids,string fkName) { if (_Options == null||_Options.OneToManyDeleteAll==false)