title: Joins vs subqueries in linq?
body: <p>I have been using linq in combination with entity framework for a few months now and am wondering about subqueries vs joins.</p>
  
  <p>I am using subqueries a lot like this:</p>
  
  <pre><code>(from department in
        (from hospital in hospitalRepository.Hospitals
         where hospital.Id == viewModel.DestinationHospitalId
         select hospital.Departments).Single()
   select new { Value = department.Id, Text = department.Name }).ToList();
  </code></pre>
  
  <p>I never really use the join keyword because to me it feel a bit too databasey. I think to do the join I need foreign keys in my domain objects which I don't really like and I feel subqueries are more intuitive. However, I almost always see people use joins in linq, which makes me wonder whether joins are much better or that people are just used to using joins from SQL. </p>
  
  <p>Furthermore, I ran into a problem with my subqueries that when the <code>Hospitals</code> ObjectSet doesn't contain a hospital with the id I want. I don't know how to make the subquery return an empty collection. Apparently the default for a list is <code>null</code>. Now I use Single and catch the exception, however I would prefer that my query would just return an empty list. </p>
  
  <p>Should I just start using joins? Shouldn't I want my query to return an empty list and handle that case as an exception? Would it have been better if the default for a list would have been an empty one?</p>
  
  <p>Some background: The purpose of this query is to populate a dropdownbox in my view based on a selected value of another dropdownlist. The other dropdownlist could have no selection which would require the first dropdownlist to be empty. So it's not <em>really</em> an exception.</p>
  
  <p>Thanks in advance.</p>