Synchronization code

This commit is contained in:
sunkaixuan 2023-12-12 13:05:34 +08:00
parent 3b86123ce7
commit df352b8b6b

View File

@ -41,8 +41,9 @@ namespace SqlSugar
children.AddRange(childs); children.AddRange(childs);
} }
} }
var isTreeChild = GetIsTreeChild(parentEntity, thisEntity);
Check.ExceptionEasy(thisPkColumn == null, $"{thisEntity.EntityName}need primary key", $"实体{thisEntity.EntityName}需要主键"); Check.ExceptionEasy(thisPkColumn == null, $"{thisEntity.EntityName}need primary key", $"实体{thisEntity.EntityName}需要主键");
if (NotAny(name)) if (NotAny(name) || isTreeChild)
{ {
InsertDatas(children, thisPkColumn); InsertDatas(children, thisPkColumn);
} }
@ -53,6 +54,11 @@ namespace SqlSugar
SetNewParent<TChild>(thisEntity, thisPkColumn); SetNewParent<TChild>(thisEntity, thisPkColumn);
} }
private bool GetIsTreeChild(EntityInfo parentEntity , EntityInfo thisEntity)
{
return this.NavContext?.Items?.Any() == true && parentEntity.Type == thisEntity.Type;
}
private static bool ParentIsPk(EntityColumnInfo parentNavigateProperty) private static bool ParentIsPk(EntityColumnInfo parentNavigateProperty)
{ {
return parentNavigateProperty != null && return parentNavigateProperty != null &&