title: Conditional Joins in LINQ
body: <p>I have a parent child table relationship. In the example below Foo has a FooID and a nullable ParentFooID that points to a parent record.</p>
  
  <p>The Bar table is always linked to the parent record. This is the SQL I use to get the result.</p>
  
  <pre><code>Select * from Foo f
  JOIN  Bar b
    ON b.FooID =  
       CASE 
         WHEN f.ParentFooID is null
           THEN f.FooID
         ELSE f.ParentFooID
       END
  </code></pre>
  
  <p>I'm having a bit of trouble getting this into a LINQ query. I'd like to avoid a cross join like the following:</p>
  
  <pre><code>    var q = from f in Foo 
              from b in Bar 
              where  b.FooID == (f.ParentFooID ?? f.FooID)
  </code></pre>
  
  <p>Cheers,</p>
  
  <p>Daniel</p>