1

I am creating a complex structure with EF 4.1. A very simplified version looks like:

var top = from x in _context.top
          select new TopView 
          {
            field = top.field,
            sub = ( from y in x.RelatedTable
                    select new SubView
                    {
                      subfield = y.subfield,
                      subsub = ( from z in y.AnotherRelatedTable
                                 select new SubSubView
                                 {
                                   subsubfield = z.subsubfield
                                 }
                               )
                    }
                  )
          }

The viewmodels look like:

public class TopView {
   string field { get; set; }
   IEnumerable<SubView> sub { get; set; }
}

public class SubView {
   string subfield { get; set; }
   IEnumerable<SubSubView> sub { get; set; }
}

public class SubSubView {
   string subsubfield { get; set; }
}

When I retrieve a TopView object in my controller (but don't access any of the properties, after a few seconds, my output shows:

The thread '<No Name>' (0x1b44) has exited with code 0 (0x0).
The thread '<No Name>' (0x1448) has exited with code 0 (0x0).
The thread '<No Name>' (0xf34) has exited with code 0 (0x0).

Now, when I remove the inner-most structure so that SubView looks like:

                    select new SubView
                    {
                      subfield = y.subfield
                    }

And re-run, I only get two of the exit messages.

Does each nested query run in its own thread? Are the messages something to worry about?

chris
  • 36,094
  • 53
  • 157
  • 237

1 Answers1

1

Does each nested query run in its own thread?

No.

Are the messages something to worry about?

No.

What you should worry about is the N+1 problem.

Community
  • 1
  • 1
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • Can you explain where these messages are coming from, and why it's safe to ignore them? – chris Mar 07 '12 at 19:04
  • @chris, I presume that you are seeing those messages in the Visual Studio debugger. It shows all threads. When you are working on a multithreaded application such as ASP.NET and run in debug mode, VS will trace all threads and in a multithreaded application you have lots of threads involved to service the requests. They all indicate return code of 0 meaning that those threads completed successfully doing whatever they were supposed to do (I guess service your worker requests), so you can safely ignore them. – Darin Dimitrov Mar 07 '12 at 19:06