I was wondering if there is a neat way do to this, that DOESN'T use any kind of while loop or similar, preferably that would run against Linq to Entities as a single SQL round-trip, and also against Linq To Objects.
I have an entity - Forum
- that has a parent-child relationship going on. That is, a Forum
may (or in the case of the top level, may not) have a ParentForum
, and may have many ChildForums
. A Forum
then contains many Posts
.
What I'm after here is a way to get all the Posts
from a tree of Forums
- i.e. the Forum
in question, and all it's children, grandchildren etc. I don't know in advance how many sub-levels the Forum
in question may have.
(Note - I know this example isn't necessarily a valuable use case, but the Forum object model one is one that is familiar to most people, and so serves as a generic and accessible premise rather than my actual domain model.)