.net中使用linq递归查询
public IEnumerable<NodeData> GetSonID(string p_id) { //获取表中所有数据 INodeDataService NodeDataService = new NodeDataService(); var entity = NodeDataService.FindAll(); //查询父节点和给定节点id相同的节点 var query = from c in entity where c.ParentId == p_id select c; var list = query.ToList(); //递归查询节点id和已经查询出来的节点的父节点相同的节点 return query.ToList().Concat(query.ToList().SelectMany(t => GetSonID(t.NodeID))); }
时间: 2024-10-22 06:33:39