title: Entity Framework Eager Loading not working
body: <p>I want to load a list of objects from db using Entity Framework 6 and Eager loading. But Entity Framework instead uses lazy loading. I've used SQL profiler and the queries are executed when a property referring to the child entities is accessed.
  By using the 'Include' you suppose to load related entities in one go but it's not happening. My Code is presented below:</p>
  
  <pre><code>    using (var flightsPricingRulesContext = new FlightsPricingRulesDbContext())
      {
         flightsPricingRulesContext.Configuration.ValidateOnSaveEnabled = false;
         flightsPricingRulesContext.Configuration.AutoDetectChangesEnabled = false;
  
  
     var filter = PredicateBuilder.True&lt;FlightsPricingRulesDataAccess.Models.ServiceFee&gt;();
  
      if (!String.IsNullOrEmpty(selectedMarketId))
      {
         var selectedMarket = Int32.Parse(selectedMarketId);
         filter = filter.And(sf =&gt; sf.MarketId == selectedMarket);
      }
  
      if (!String.IsNullOrEmpty(selectedApplicationTypeId))
      {
         var selectedAppplicationType = Int32.Parse(selectedApplicationTypeId);
         filter = filter.And(sf =&gt; sf.ApplicationType == selectedAppplicationType);
      }
  
      var Query = 
      from P in flightsPricingRulesContext.ServiceFee.AsExpandable().Where(filter)select P;
  
      switch (orderby)
      {
        case null:
        case "":
        case "Id":
        Query = String.IsNullOrEmpty(orderbydirection) || orderbydirection  == "ASC"
        ?Query.OrderBy(p =&gt; p.Id): Query.OrderByDescending(p =&gt; p.Id);
        break;
  
        case "market":
        Query = String.IsNullOrEmpty(orderbydirection) || orderbydirection == "ASC"
        ? Query.OrderBy(p =&gt; p.MarketId)
        : Query.OrderByDescending(p =&gt; p.MarketId);
        break;
      }
  
      var takeitems = 10 ;
      var skipitems = (Int32.Parse(page) - 1) * 10);
  
      //BY USING INCLUDE EAGER LOADING IS ENABLED
      Query = Query.Skip(skipitems).Take(takeitems).
      Include(sf =&gt; sf.ServiceFeeZone.Select(sfz =&gt; sfz.Zone)).
      Include(sf =&gt; sf.ServiceFeeCarrier).
      Include(sf =&gt; sf.ServiceFeeClassOfService).
      Include(sf =&gt; sf.ServiceFeeDate).
      Include(sf =&gt; sf.ServiceFeeMarkUpAssignment).
      Include(sf =&gt; sf.ServiceFeeAssignment);
  
      var results = Query.ToList();//HERE A COMPLETE QUERY SHOULD BE 
      //SENT TO THE DB FOR RETRIEVING ENTITES INCLUDING THEIR CHILDREN
  
      var totalresults = flightsPricingRulesContext.ServiceFee.AsExpandable().Count(filter);
  
      var pagedservicefees = new PagedServiceFee();
      pagedservicefees.totalitems = totalresults.ToString();
      pagedservicefees.servicefees = new List&lt;FlightsPricingRules.Models.ServiceFee&gt;();
  
  
      foreach (var servicefeedto in results)
      {
         var servicefee = new FlightsPricingRules.Models.ServiceFee();
  
         servicefee.id = servicefeedto.Id.ToString();
         servicefee.marketId = servicefeedto.MarketId.ToString();
          //.....
          //SOME MORE PROPERTIES
          //                      
  
      //CHILD ENTITIES
  
          //Zones
          servicefee.zones = new List&lt;Zone&gt;();
          //HERE AN   ADDITIONAL QUERY IS MADE TO LOAD THE CHILD ENTITIES-WHY?
          foreach (var zonedto in servicefeedto.ServiceFeeZone)
          {
             var zone = new Zone();
             zone.id = zonedto.ZoneId.ToString();
             zone.name = zonedto.Zone.Name;
             servicefee.zones.Add(zone);
           }
  
            //Carriers
            servicefee.carriers = new List&lt;Carr&gt;();
            //ALSO HERE AND ADDITIONAL QUERY IS MADE
            foreach (var carrierdto in servicefeedto.ServiceFeeCarrier)
            {
              var carrier = new Carr();
              carrier.id = carrierdto.AirlineId.ToString();
              servicefee.carriers.Add(carrier);
             }
  
  
        pagedservicefees.servicefees.Add(servicefee);
     }
     //.......
     //SOME MORE CHILD ENTITIES
     //
  
  
  return Json(pagedservicefees, JsonRequestBehavior.DenyGet);
  
  }                
  </code></pre>