1

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?

Community
  • 1
  • 1
Luke101
  • 63,072
  • 85
  • 231
  • 359
  • There's no indication of SQL server in here *at all*. Where does the SQL part come in? This looks more likely to be XML... please give more context. – Jon Skeet Aug 01 '12 at 16:55
  • 2
    @JonSkeet - Not xml, he linked to your own code... don't you recognize it? :) – gilly3 Aug 01 '12 at 16:59
  • 1
    @gilly3: I didn't at the time, no :) But I still can't see where SQL Server comes in. The answer at the moment can only be "maybe". – Jon Skeet Aug 01 '12 at 16:59
  • 2
    The simplest way to know would be to **check**. Turn on your SQL Server Profiler and see how many queries are being made. – Adi Lester Aug 01 '12 at 17:12
  • I assumed the original question (http://stackoverflow.com/a/4814278/184773) was referring to sql server. Now that i look at it - it does not refer to sql server at all. i will delete this question. – Luke101 Aug 01 '12 at 19:48

1 Answers1

2

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.

Mark Byers
  • 811,555
  • 193
  • 1,581
  • 1,452