Browse Source

Update InsertNav

SqlSugar5
sunkaixuan 2 years ago
parent
commit
41c2b1edf6
  1. 12
      Src/Asp.Net/SqlSugar/Abstract/ExecuteNavProvider/InsertNavProviderOneToMany.cs

12
Src/Asp.Net/SqlSugar/Abstract/ExecuteNavProvider/InsertNavProviderOneToMany.cs

@ -24,6 +24,10 @@ namespace SqlSugar
{
parentPkColumn = parentNavColumn;
}
if (ParentIsPk(parentNavigateProperty))
{
parentPkColumn = this._ParentEntity.Columns.FirstOrDefault(it => it.IsPrimarykey);
}
foreach (var item in parentList)
{
var parentValue = parentPkColumn.PropertyInfo.GetValue(item);
@ -42,6 +46,14 @@ namespace SqlSugar
SetNewParent<TChild>(thisEntity, thisPkColumn);
}
private static bool ParentIsPk(EntityColumnInfo parentNavigateProperty)
{
return parentNavigateProperty != null &&
parentNavigateProperty.Navigat != null &&
parentNavigateProperty.Navigat.NavigatType == NavigateType.OneToMany &&
parentNavigateProperty.Navigat.Name2==null;
}
private EntityColumnInfo GetParentPkColumn()
{
EntityColumnInfo parentPkColumn = _ParentPkColumn;

Loading…
Cancel
Save