title: Dynamic Include statements for eager loading in a query - EF 4.3.1
body: <p>I have this method:</p>
  
  <pre><code>public CampaignCreative GetCampaignCreativeById(int id)
          {
              using (var db = GetContext())
              {
                  return db.CampaignCreatives
                      .Include("Placement")
                      .Include("CreativeType")                    
                      .Include("Campaign")
                      .Include("Campaign.Handshake")
                      .Include("Campaign.Handshake.Agency")
                      .Include("Campaign.Product")
                      .AsNoTracking()
                      .Where(x =&gt; x.Id.Equals(id)).FirstOrDefault();
              }
          }
  </code></pre>
  
  <p>I would like to make the list of Includes dynamic. I tried:</p>
  
  <pre><code>public CampaignCreative GetCampaignCreativeById(int id, string[] includes)
          {
              using (var db = GetContext())
              {
                  var query = db.CampaignCreatives;
  
                  foreach (string include in includes)
                  {
                      query = query.Include(include);
                  }
  
                  return query.AsNoTracking()
                      .Where(x =&gt; x.Id.Equals(id)).FirstOrDefault();                    
              }
          }
  </code></pre>
  
  <p>But it didn't compile. I got this error:</p>
  
  <p><em>Cannot implicitly convert type 'System.Data.Entity.Infrastructure.DbQuery' to 'System.Data.Entity.DbSet'. An explicit conversion exists (are you missing a cast?)</em></p>
  
  <p>Does anyone know how to make the list of Includes dynamic?</p>
  
  <p>Thanks</p>