title: EF Eager loading include multiple
body: <p>I have this Repository:</p>
  
  <pre><code>public class Repository&lt;T&gt; : IRepository&lt;T&gt; where T : class
  {
      private readonly DbContext context;
      private readonly DbSet&lt;T&gt; dbEntitySet;
  
      public Repository(DbContext context)
      {
          if (context == null)
              throw new ArgumentNullException("context");
  
          this.context = context;
          this.dbEntitySet = context.Set&lt;T&gt;();
      }
  
      public IEnumerable&lt;T&gt; GetAll()
      {
          return this.dbEntitySet;
      }
  
      public IEnumerable&lt;T&gt; GetAll(string include)
      {
          return this.dbEntitySet.Include(include);
      }
  
      public IEnumerable&lt;T&gt; GetAll(string[] includes)
      {
          IQueryable&lt;T&gt; query = context.Set&lt;T&gt;();
          foreach (var include in includes)
              query.Include(include);
  
          return query;
      }
  
      public void Create(T model)
      {
          this.dbEntitySet.Add(model);
      }
  
      public void Update(T model)
      {
          this.context.Entry&lt;T&gt;(model).State = EntityState.Modified;
      }
  
      public void Remove(T model)
      {
          this.context.Entry&lt;T&gt;(model).State = EntityState.Deleted;
      }
  
      public void Dispose()
      {
          this.context.Dispose();
      }
  }
  </code></pre>
  
  <p>And I have a service which looks like this:</p>
  
  <pre><code>public class Service&lt;T&gt; where T : class
  {
      private readonly IRepository&lt;T&gt; repository;
  
      protected IRepository&lt;T&gt; Repository
      {
          get { return this.repository; }
      }
  
      internal Service(IUnitOfWork unitOfWork)
      {
          this.repository = unitOfWork.GetRepository&lt;T&gt;();
      }
  }
  </code></pre>
  
  <p>My pages service looks like this (simplified):</p>
  
  <pre><code>public class PageService : Service&lt;Page&gt;
  {
  
      // ...
  
      public IList&lt;Page&gt; GetPublished()
      {
          return this.Repository.GetAll(new string[] { "ForbiddenUsers", "ForbiddenGroups" }).Where(model =&gt; model.Published).ToList();
      }
  
      // ...
  
  }
  </code></pre>
  
  <p>and just for clarity my <strong>Page</strong> looks like this:</p>
  
  <pre><code>public enum PageType
  {
      Root,
      System,
      Page,
      Link,
      Group
  }
  
  public partial class Page
  {
      public int Id { get; set; }
      public System.DateTime DateCreated { get; set; }
      public string CreatedById { get; set; }
      public Nullable&lt;System.DateTime&gt; DateModified { get; set; }
      public string ModifiedById { get; set; }
      public string CompanyId { get; set; }
      public string Name { get; set; }
      public string Description { get; set; }
      public string FileName { get; set; }
  
      public string Path { get; set; }
      public string ViewData { get; set; }
      public string ViewTitle { get; set; }
  
      public string Link { get; set; }
      public bool Published { get; set; }
      public PageType Type { get; set; }
      public int Order { get; set; }
      public string Lineage { get; set; }
      public Nullable&lt;int&gt; ParentId { get; set; }
      public bool Restricted { get; set; }
      public bool Deleted { get; set; }
  
      public Company Company { get; set; }
      public User CreatedBy { get; set; }
      public User ModifiedBy { get; set; }
      public Page Parent { get; set; }
      public MenuPage MenuPage { get; set; }
      public ICollection&lt;Page&gt; Pages { get; set; }
      public ICollection&lt;User&gt; ForbiddenUsers { get; set; }
      public ICollection&lt;Group&gt; ForbiddenGroups { get; set; }
  }
  </code></pre>
  
  <p>When I run this code, <strong>ForbiddenUsers</strong> and <strong>ForbiddenGroups</strong> are always null.
  If I examine the call stack and I can see that the query that is generated looks like this:</p>
  
  <pre><code>SELECT 
  [Extent1].[Id] AS [Id], 
  [Extent1].[DateCreated] AS [DateCreated], 
  [Extent1].[CreatedById] AS [CreatedById], 
  [Extent1].[DateModified] AS [DateModified], 
  [Extent1].[ModifiedById] AS [ModifiedById], 
  [Extent1].[CompanyId] AS [CompanyId], 
  [Extent1].[Name] AS [Name], 
  [Extent1].[Description] AS [Description], 
  [Extent1].[FileName] AS [FileName], 
  [Extent1].[Path] AS [Path], 
  [Extent1].[ViewData] AS [ViewData], 
  [Extent1].[ViewTitle] AS [ViewTitle], 
  [Extent1].[Link] AS [Link], 
  [Extent1].[Published] AS [Published], 
  [Extent1].[Type] AS [Type], 
  [Extent1].[Order] AS [Order], 
  [Extent1].[Lineage] AS [Lineage], 
  [Extent1].[ParentId] AS [ParentId], 
  [Extent1].[Restricted] AS [Restricted], 
  [Extent1].[Deleted] AS [Deleted]
  FROM [dbo].[Pages] AS [Extent1]
  </code></pre>
  
  <p>As you can see, that is completely ignoring my includes.</p>
  
  <p>If I change my service method to this:</p>
  
  <pre><code>public IList&lt;Page&gt; GetPublished()
  {
      return this.Repository.GetAll("ForbiddenUsers").Where(model =&gt; model.Published).ToList();
  }
  </code></pre>
  
  <p>and run my code, <strong>ForbiddenUsers</strong> is now populated and the call stack shows the correct generated query (too big to paste in here).</p>
  
  <p>I need to allow multiple includes but I can not figure out why they are not working....</p>
  
  <p>Any help would be greatly appreciated....</p>