Here is the code:
public IEnumerable<SomeItem> DescendantsAndSelf()
{
yield return this;
foreach (var item in Children.SelectMany(x => x.DescendantsAndSelf())
{
yield return item;
}
}
I got this code from here:
https://stackoverflow.com/a/4814278/184773
This is a recursive linq query. i want to implement this but afraid it my bring my server down. Do you know if this performans multiple run trips to the server?
If you want to make just one call you could implement a recursive query in SQL using a recursive CTE and expose it to your application as a stored procedure which can be called from LINQ.