title: Entity Framework with Include and Select together
body: <p>I have the following entities ( pseudo code to save space)</p>
  
  <pre><code>Program [ int Id, 
            string Name, 
            List&lt;ProgramFoodType&gt; ProgramFoodTypes, 
            List&lt;ProgramFood&gt; ProgramFoods]
  
  ProgramFoodType[ int Id, int ProgramId, int Type, bool IsActive]
  ProgramFood [ int Id, int ProgramId, Food Food, FoodType FoodType]
  Food [int Id, string Name]
  FoodType [int Id, string Name]
  </code></pre>
  
  <p>my task is to get single <code>Program</code> with its related <code>ProgramFoodTypes</code> with condition ProgramFoodType should be active and <code>ProgramFoods</code> with related entities <code>Food</code> and <code>FoodType</code></p>
  
  <p>I used the following so far</p>
  
  <p>1- the below query will retrieve the details of <code>ProgramFoodTypes</code> and <code>ProgramFoods</code> but it will bring all active and inactive <code>ProgramFoodTypes</code></p>
  
  <pre><code>var program = mEntities.Programs
                            .Include(p =&gt;p.ProgramFoodTypes)
                            .Include(p =&gt;p.ProgramFoods.Select(f =&gt;f.Food))
                            .InClude(p =&gt;p.ProgramFoods.Select( f =&gt;f.FoodType))
                            .Where(m =&gt;m.Id== Id);
  </code></pre>
  
  <p>2- the below query will retrieve the details but missing the <code>Food</code> and <code>FoodType</code></p>
  
  <pre><code>var program = (from p in mEntities.Programs
                where p.Id ==Id
                select new {
                   Program = p,
                   ProgramFoodTypes = from pf in p.ProgramFoodTypes
                                      where pf.IsActive
                                      select pf,                  
                   ProgramFoods = p.ProgramFoods // here i can't add include statement
                }).ToArray().Select(m =&gt; m.Program);
  </code></pre>
  
  <p>how to include the food and food type in the second query?</p>