title: Entity Framework and repository pattern problem
body: <p>I am using generic repository pattern with methods:</p>
  
  <p><code></p>
  
  <pre><code>    private ObjectQuery&lt;T&gt; ObjectQueryList()
      {
          var list = CamelTrapEntities.CreateQuery&lt;T&gt;(EntitySetName);
          return list;
      }
  </code></pre>
  
  <p></code>
  <code></p>
  
  <pre><code>    public IQueryable&lt;T&gt; List()
      {
          return ObjectQueryList();
      }
  </code></pre>
  
  <p></code></p>
  
  <p>Metod List() returns IQueryable&#60;T&#62;, becase IQueryable&#60;T&#62; is easy to mock. I also have extension method:</p>
  
  <p><code></p>
  
  <pre><code>    public static IQueryable&lt;T&gt; Include&lt;T&gt;(this IQueryable&lt;T&gt; obj, string path)
      {
          if (obj is ObjectQuery&lt;T&gt;)
              (obj as ObjectQuery&lt;T&gt;).Include(path);
  
          return obj;
      }
  </code></pre>
  
  <p></code></p>
  
  <p>This method is used outside of repository to get entity list with navigation properties already loaded, for example: List.Include("CreatedBy"). The problem is that it doesn't work. All includes are ignored. when I change List() method to</p>
  
  <p><code></p>
  
  <pre><code>    public ObjectQuery&lt;T&gt; List()
      {
          return ObjectQueryList();
      }
  </code></pre>
  
  <p></code></p>
  
  <p>everything works fine. </p>
  
  <p>How should I implement repository pattern to be able to execute more complex queries?</p>