2 B 1 3 C 2 4 D 3 如何删除所有孩子都在使用Entity框架和jqxTree删除A? 我尝试过:HelloI have a tree :Id Title ParentId1 A 02 B 13 C 24 D 3How can I remove all children on removing "A" using Entity framework and jqxTree?What I have tried:TableTree _TT = _Entity.TableTree.where(c => c.Id == _RemoveArgs.Id).singleorDifault();if(_TT != null){ _Entity.TableTree.Remove(_TT);}TableTree _TT2 = _Entity.TableTree.where(c => c.ParentId == _RemoveArgs.Id).singleorDifault();if(_TT2 != null){ _Entity.TableTree.Remove(_TT2);} _RemoveArgs是我在javascript文件中传递json数据的类。 提前致谢_RemoveArgs is the class that I pass json data in javascript file to it.Thanks in advance推荐答案尝试这样的事情:Try something like this:TableTree node = _Entity.TableTree.SingleOrDefault(c => c.Id == _RemoveArgs.Id);if (node != null){ var nodesToRemove = new List<TableTree>(); nodesToRemove.Add(node); var children = _Entity.TableTree.Where(c => c.ParentId == node.Id).ToList(); if (children.Count != 0) { var tree = new Queue<IList<TableTree>>(); tree.Enqueue(children); while (tree.Count != 0) { IList<TableTree> current = tree.Dequeue(); nodesToRemove.AddRange(current); foreach (TableTree child in current) { children = _Entity.TableTree.Where(c => c.ParentId == child.Id).ToList(); if (children.Count != 0) { tree.Enqueue(children); } } } } foreach (TableTree nodeToRemove in nodesToRemove) { _Entity.TableTree.Remove(nodeToRemove); }} 这篇关于如何在删除父节点时删除子节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 06-16 12:26