Let's say we've got this table:
WORKER
NAME ID ManagerID
------------------------
John 1 3
Sally 2 3
Paul 3 4
Jane 4 5
Jennifer 5 8
So John and Sally work for Paul, and Paul works for Jane.
For the linq query, I want to feed it Jane's ID (4) and have it return back all of her subordinates:
John 1 3
Sally 2 3
Paul 3 4
I would also need for this query to recursively go as deep as is needed. For example, maybe John has people working for him, so they would be included in the results too.
I was thinking about using SelectMany, but am not sure if this would work:
db.Worker.SelectMany(w => w.ID).Where(w => w.ID == 4).ToList();
I am using Linq-to-SQL and the query would only have this one table to work with.
How would you build this query?
Edit: here is what the model class would look like
WORKER
ID int
Name string
ManagerID int