Update db.UpdateNav

This commit is contained in:
sunkaixuan 2022-07-26 22:16:29 +08:00
parent ba684e7f4b
commit 34c106a11e
2 changed files with 12 additions and 3 deletions

View File

@ -8,7 +8,7 @@ namespace SqlSugar
{
public partial class UpdateNavProvider<Root, T> where T : class, new() where Root : class, new()
{
public NavigateType? _NavigateType { get; set; }
private void UpdateOneToMany<TChild>(string name, EntityColumnInfo nav) where TChild : class, new()
{
List<TChild> children = new List<TChild>();
@ -34,15 +34,17 @@ namespace SqlSugar
foreach (var child in childs)
{
thisFkColumn.PropertyInfo.SetValue(child, parentValue, null);
ids.Add(parentValue);
}
children.AddRange(childs);
}
ids.Add(parentValue);
}
this._Context.Deleteable<object>()
.AS(thisEntity.DbTableName)
.In(thisFkColumn.DbColumnName, ids.Distinct().ToList()).ExecuteCommand();
_NavigateType = NavigateType.OneToMany;
InsertDatas(children, thisPkColumn);
_NavigateType = null;
SetNewParent<TChild>(thisEntity, thisPkColumn);
}

View File

@ -74,7 +74,14 @@ namespace SqlSugar
Check.ExceptionEasy(pkColumn == null && NavColumn == null, $"The entity is invalid", $"实体错误无法使用导航");
x.AsUpdateable.ExecuteCommand();
InitData(pkColumn, insertData);
this._ParentList = insertData.Union(updateData).Cast<object>().ToList();
if (_NavigateType == NavigateType.OneToMany)
{
this._ParentList = children.Cast<object>().ToList();
}
else
{
this._ParentList = insertData.Union(updateData).Cast<object>().ToList();
}
}
private void InitData<TChild>(EntityColumnInfo pkColumn, List<TChild> UpdateData) where TChild : class, new()