title: Problem using Include() when serializing Entity Framework 4 POCO classes with WCF
body: <p>I have a WCF service with an Entity Framework 4 model, using POCO classes that are serialized and sent over to client applications. I have <code>LazyLoadingEnabled</code> and <code>ProxyCreationEnabled</code> set to <code>false</code>, and I'm using Linq to Entites to query an Entity, and return it via <code>List&lt;&gt;</code> to the client. Everything goes perfect when I don't use Include():</p>
  
  <pre><code>public List&lt;TBLTable1&gt; GetTBLTable1(string pCode)
  {
    using (PcFactoryEntities oPcFactoryDB = new PcFactoryEntities())
    {
      oPcFactoryDB.ContextOptions.ProxyCreationEnabled = false;
      oPcFactoryDB.ContextOptions.LazyLoadingEnabled = false;
      var oRS = oPcFactoryDB.TBLTable1
        .Where(c =&gt; c.Code == pCode).ToList();
      XmlObjectSerializer serializer = new DataContractSerializer(typeof(TBLTable1));
      serializer.WriteObject(new XmlTextWriter(Console.Out) { Formatting = Formatting.Indented }, oRS[0]);
      return oRS;
    }
  }
  </code></pre>
  
  <p>After the Linq query, I use the serializer to simulate the serialization process that happens when the POCO class is sent to the client, and I works great. However, when I add an Include() to load one of the navigation list for the class, it starts serializing all of <code>Table2</code>'s navigation's list as if LazyLoadingEnabled was set to true, and it goes on forever serializing probably the whole database!</p>
  
  <pre><code>public List&lt;TBLTable1&gt; GetTBLTable1(string pCode)
  {
    using (PcFactoryEntities oPcFactoryDB = new PcFactoryEntities())
    {
      oPcFactoryDB.ContextOptions.ProxyCreationEnabled = false;
      oPcFactoryDB.ContextOptions.LazyLoadingEnabled = false;
      var oRS = oPcFactoryDB.TBLTable1
        .Include("TBLTable2")
        .Where(c =&gt; c.Code == pCode).ToList();
      XmlObjectSerializer serializer = new DataContractSerializer(typeof(TBLTable1));
      serializer.WriteObject(new XmlTextWriter(Console.Out) { Formatting = Formatting.Indented }, oRS[0]);
      return oRS;
    }
  }
  </code></pre>
  
  <p>Why is this happening? Shouldn't the LazyLoadingEnabled set to false apply to the class included manually and return all of it's navigation lists to <code>null</code> as it happens with all of the other navigation lists for <code>Table1</code>? Is there a way to fix this so I can return with Table1 some navigations lists filled in with their navigation lists set to <code>null</code>? <br>
  Tks</p>