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.
[Association(Name="Clients_ToEmployee", Storage="_ToEmployees", ThisKey="ClientID", OtherKey="ClientID")]
[DataMember(Order=70, EmitDefaultValue=false)]
public EntitySet<ClientToEmployee> ClientToEmployees
{
get
{
if ((this.serializing &&(this._ToEmployees.HasLoadedOrAssignedValues == false)))
{
return null;
}
return this._ToEmployees;
}
set
{
this._ToEmployees.Assign(value);
}
}
When i try to serialize my resultset using
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();
It looks like at this code, see below, it always returns null
if ((this.serializing && (this._ToEmployees.HasLoadedOrAssignedValues == false)))
If i set a break point and step through the code then the above statement
this._ToEmployees.HasLoadedOrAssignedValues
is true and I get my object rather then a null being returned.
Why does it behave correctly when I am stepping through the code? Should I introduce a delay so that the Entityset object is populated?