title: LINQ to SQL "cannot access disposed object" exception
body: <p>My code is throwing an exception when I attempt to access children of an object I retrieved from the database. I am using LINQ to SQL.</p>
  
  <pre><code>using (var DC = new MyDataContext())
  {
  
      TimeSlot timeSlot = DC.TimeSlots
      .Where(w =&gt; w.FacilityID == facilityID
      .OrderByDescending(o =&gt; o.LoadDate)
      .FirstOrDefault();
  
      return timeSlot;
  
  }
  
  // Much later...
  var slotChildren = timeSlot.children; // EXCEPTION!! Cannot access a disposed object.
  </code></pre>
  
  <p>The only way I have been able to make this work is by forcing the load with <code>timeSlotForDay.LMSTimeSlotHours.Load()</code> but that feels hacky. I have a hunch that one of the main issues is <code>.FirstOrDefault()</code> because I have tried many different things, even producing a nice join using projection using this code <a href="http://pastie.org/private/zzb01oeimkpelqz14gi7q" rel="nofollow">http://pastie.org/private/zzb01oeimkpelqz14gi7q</a> that I got from this blog: <a href="https://eprystupa.wordpress.com/2009/11/26/linq-to-sql-tricks-building-efficient-queries-that-include-reference-data-or-child-entities/" rel="nofollow">https://eprystupa.wordpress.com/2009/11/26/linq-to-sql-tricks-building-efficient-queries-that-include-reference-data-or-child-entities/</a>, running the generated SQL in Microsoft SQL Server produces the expected results but after I return. But it seems like something is throwing away my data instead of loading it. My other alternatives would be to return the children in a seperate method entirely. This seems silly though because I have plenty of other methods in my project where I can grab one entity and then reach through to all the other children without these issues.</p>