title: Having troubles loading related entities (Eager Load) with ObjectContext.CreateQuery (Entity Framework and Repositories)
body: <p>Here's a bunch of things I tried... hopefully you can extrapolate from it what I'm trying to do and what I'm doing wrong. Okay so I'm having problems with loading related entities when using this DoQuery:</p>
  
  <pre><code>   public ObjectQuery&lt;E&gt; DoQuery(ISpecification&lt;E&gt; where)
     {
          return (ObjectQuery&lt;E&gt;)_ctx.CreateQuery&lt;E&gt;("[" + typeof(E).Name + "]").Where(where.EvalPredicate);
     }
  </code></pre>
  
  <p>If I just use this, I end up getting an object back that contains all proper parameters except the ones that are related entities... ie. if one is a UserID that's referenced to the User table, I do not get back the User object as well.</p>
  
  <p>I read up that you can do a .Include("User") to do an Eager Load of the entity... but it doesn't work when I try this:</p>
  
  <pre><code>public ObjectQuery&lt;E&gt; DoQuery(ISpecification&lt;E&gt; where)
  {
       return (ObjectQuery&lt;E&gt;)_ctx.CreateQuery&lt;E&gt;("[" + typeof(E).Name + "]").Include("User").Where(where.EvalPredicate);
  }
  </code></pre>
  
  <p>I also checked to make sure the Entity Set Name and model name are "User", which they are. The only other thing I could think of is to put multiple things in the <code>("[" + typeof(E).Name + "]")</code> but I'm not sure how to include multiple entities in there... Here's what I tried since I saw someone said you could load multiple by putting a . inbetween.</p>
  
  <pre><code>public ObjectQuery&lt;E&gt; DoQuery(ISpecification&lt;E&gt; where)
  {
       return (ObjectQuery&lt;E&gt;)_ctx.CreateQuery&lt;E&gt;("[" + typeof(E).Name + "].[User]").Where(where.EvalPredicate);
  }
  </code></pre>
  
  <p>But that didn't work...</p>
  
  <p>If I'm not on the right track please let me know. Does anyone know how to load the related entities when using ObjectContext.CreateQuery? Any suggestions or insight helps.</p>
  
  <p>Thanks,<br/>
  Matt</p>