Using Linq to access I have a self-referencing collection in memory I would like to get all records that are beneath a given ID. I would also like to pass a depth level so it would not search children records after the level was reached. The level could help avoid a circular reference of self-referencing and endless loop
So here is my in memory object
ID NAME PARENTID
1 Bob null
2 Cody 1
3 Duke 1
4 Eric 2
5 Fred 4
6 Greg 5
Example if the user pass in the following ID=4 MAXLEVEL = 3 they would see the following results
4-Eric,
5-Fred,
6-Greg
The results should be flattened and not hierarchical. What would be the best approach using Linq thanks for you advise and help.