我收到以下错误: “已删除的对象将通过级联重新保存(从关联中删除已删除的对象)”
我已将整个ajax调用修剪为以下内容:
[HttpPost]
[UnitOfWork(Scope = FilterScope.Result)]
public ActionResult SaveEditMode(long id, AddTrackedRowViewModel model, string editMode, List<string> elementNames, string provisionData)
{
var cell = _supplementCoordinator.GetSupplement(id).TrackedTables.First(x => x.Name == model.Name).TrackedRows.First(x => x.Ordinal == model.Ordinal).TrackedCells.First(x => x.Name == "Detail");
_supplementCoordinator.RemoveChildren(cell);
return Json( new {Success = true});
}
public bool RemoveChildren(TrackedNode parentNode)
{
foreach (TrackedField trackedField in parentNode.ChildNodes)
{
_trackedFieldRepository.Delete(trackedField);
}
return true;
}
我的映射如下
mapping.HasMany(x => x.ChildNodes).KeyColumn("ParentNodeId").Inverse();
mapping.References(x => x.ParentNode);
答案 0 :(得分:1)
只需从错误提示中删除父集合中的子节点:
public bool RemoveChildren(TrackedNode parentNode)
{
foreach (TrackedField trackedField in new List<TrackField>(parentNode.ChildNodes))
{
_trackedFieldRepository.Delete(trackedField);
_parentNode.Remove(trackField);
}
return true;
}