title: Entity Framework, how to manually produce inner joins with LinQ to entitites
body: <p>Let's imagine I have an table called Foo with a primary key FooID and an integer non-unique column Bar. For some reason in a SQL query I have to join table Foo with itself multiple times, like this:</p>
  
  <p><code>SELECT * FROM Foo f1 INNER JOIN Foo f2 ON f2.Bar = f1.Bar INNER JOIN Foo f3 ON f3.Bar = f1.Bar...</code></p>
  
  <p>I have to achieve this via LINQ to Entities.  </p>
  
  <p>Doing </p>
  
  <p><code>ObjectContext.Foos.Join(ObjectContext.Foos, a =&gt; a.Bar, b =&gt; b.Bar, (a, b) =&gt; new {a, b})</code> </p>
  
  <p>gives me LEFT OUTER JOIN in the resulting query and I need inner joins, this is very critical.</p>
  
  <p>Of course, I might succeed if in edmx I added as many associations of Foo with itself as necessary and then used them in my code, Entity Framework would substitute correct inner join for each of the associations. The problem is that at design time I don't know how many joins I will need. OK, one workaround is to add as many of them as reasonable...</p>
  
  <p>But, if nothing else, from theoretical point of view, is it at all possible to create inner joins via EF without explicitly defining the associations?</p>
  
  <p>In LINQ to SQL there was a (somewhat bizarre) way to do this via GroupJoin, like this:</p>
  
  <p><code>ObjectContext.Foos.GroupJoin(ObjectContext.Foos, a =&gt; a.Bar, b =&gt; b.Bar, (a, b) =&gt; new {a, b}).SelectMany(o = &gt; o.b.DefaultIfEmpty(), (o, b) =&gt; new {o.a, b)</code></p>
  
  <p>I've just tried it in EF, the trick does not work there. It still generates outer joins for me.</p>
  
  <p>Any ideas?</p>