title: Serialization in WCF/LINQ to SQL
body: <p>I created my dbml file with the tables that i need. One of the method generated is as such, names have been changed and it is not syntactically correct. But my code compiles with the original method created.</p>
  
  <pre><code>[Association(Name="Clients_ToEmployee", Storage="_ToEmployees", ThisKey="ClientID", OtherKey="ClientID")]
  [DataMember(Order=70, EmitDefaultValue=false)]
  public EntitySet&lt;ClientToEmployee&gt; ClientToEmployees
  {
      get
      {
          if ((this.serializing &amp;&amp;(this._ToEmployees.HasLoadedOrAssignedValues == false)))
          {
              return null;
          }
          return this._ToEmployees;
      }
      set
      {
          this._ToEmployees.Assign(value);
      }
  }
  </code></pre>
  
  <p>When i try to serialize my resultset using</p>
  
  <pre><code> DataContractSerializer ser =
                  new DataContractSerializer(clientObj.GetType());
  var memStream = new System.IO.MemoryStream();
  ser.WriteObject(memStream ,clientObj);
  memStream .Seek(0, System.IO.SeekOrigin.Begin);
  var streamReader = new System.IO.StreamReader(memStream );
  var xml = streamReader.ReadToEnd();
  </code></pre>
  
  <p>It looks like at this code, see below, it always returns null</p>
  
  <pre><code>if ((this.serializing &amp;&amp; (this._ToEmployees.HasLoadedOrAssignedValues == false)))
  </code></pre>
  
  <p>If i set a break point and step through the code then the above statement </p>
  
  <pre><code>this._ToEmployees.HasLoadedOrAssignedValues
  </code></pre>
  
  <p>is true and I get my object rather then a null being returned.</p>
  
  <p>Why does it behave correctly when I am stepping through the code? Should I introduce a delay so that the Entityset object is populated?</p>