title: Inner join and outer join options in Entity Framework 4.0
body: <p>I am using EF 4.0 and I need to implement query with one inner join and with N outer joins
  I started to implement this using different approaches but get into trouble  at some point.</p>
  
  <p>Here is two examples how I started of doing this using <code>ObjectQuery&lt;'T'> and Linq to Entity</code></p>
  
  <p>1)Using <code>ObjectQuery&lt;'T'></code> I implement flexible outer join but I don't know how to perform inner join with entity Rules in that case (by default Include("Rules") doing outer join, but i need to inner join by Id).</p>
  
  <pre><code>    public static IEnumerable&lt;Race&gt; GetRace(List&lt;string&gt; includes, DateTime date)
      {
          IRepository repository = new Repository(new BEntities());
  
          ObjectQuery&lt;Race&gt; result = (ObjectQuery&lt;Race&gt;)repository.AsQueryable&lt;Race&gt;();
  
          //perform outer joins with related entities
          if (includes != null)                   
              foreach (string include in includes)
                  result = result.Include(include);
  
  
          //here i need inner join insteard of default outer join
          result = result.Include("Rules"); 
  
          return result.ToList();
      }
  </code></pre>
  
  <p>2)Using Linq To Entity I need to have kind of outer join(somethin like in GetRace()) where i may pass a List with entities to include) and also i need to perform correct inner join with entity Rules</p>
  
  <pre><code>    public static IEnumerable&lt;Race&gt; GetRace2(List&lt;string&gt; includes, DateTime date)
      {
          IRepository repository = new Repository(new BEntities());
  
          IEnumerable&lt;Race&gt; result = from o in repository.AsQueryable&lt;Race&gt;()
                                     from b in o.RaceBetRules
                                     select new
                                     {
                                       o
                                     });
  
          //I need here:
          // 1. to perform the same way inner joins with related entities like with ObjectQuery above
  
          //here i getting List&lt;AnonymousType&gt; which i cant cast to 
          //IEnumerable&lt;Race&gt; when i did try to cast like 
          //(IEnumerable&lt;Race&gt;)result.ToList(); i did get error:
          //Unable to cast object of type 
          //'System.Collections.Generic.List`1[&lt;&gt;f__AnonymousType0`1[BetsTipster.Entity.Tip.Types.Race]]' 
          //to type 
          //'System.Collections.Generic.IEnumerable`1[BetsTipster.Entity.Tip.Types.Race]'.
          return result.ToList();
      }
  </code></pre>
  
  <p>May be someone have some ideas about that.</p>