0

,我發現了以下錯誤: 刪除的對象 - 自參照表

「刪除對象將通過級聯(從協會刪除已刪除對象)重新保存」我已經削減的全部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); 

回答

1

剛剛從父集合中移除子節點就像ERR或建議:

public bool RemoveChildren(TrackedNode parentNode) 
    { 
     foreach (TrackedField trackedField in new List<TrackField>(parentNode.ChildNodes)) 
     { 
      _trackedFieldRepository.Delete(trackedField); 
      _parentNode.Remove(trackField); 
     } 
     return true; 
    } 
+0

沒錯。新鮮的眼睛。謝謝。 – Seth