I’m switching code generators for my business objects. I was using SQL Metal, but in moving to the T4 toolbox’s generator, serialization seems to have stopped working, and it looks like the two are doing pretty much the same thing.
This is the property generated by SQL Metal (which works):
[Association(Name="FK_FamilyConfiguration_Family", Storage="_FamilyConfigurations", ThisKey="FamilyID", OtherKey="FamilyID", DeleteRule="CASCADE")]
[DataMember(Order=4, EmitDefaultValue=false)]
public EntitySet<FamilyConfiguration> FamilyConfigurations
{
get
{
if ((this.serializing
&& (this._FamilyConfigurations.HasLoadedOrAssignedValues == false)))
{
return null;
}
return this._FamilyConfigurations;
}
set
{
this._FamilyConfigurations.Assign(value);
}
}
and this is the property generated by the T4 toolbox (which does not work):
[DataMember(Order = 4, EmitDefaultValue = false)]
[Association(Name = "Family_FamilyConfiguration", Storage = "familyConfigurations", ThisKey = "FamilyID", OtherKey = "FamilyID")]
public EntitySet<FamilyConfiguration> FamilyConfigurations
{
get
{
if (this.serializing && !this.familyConfigurations.HasLoadedOrAssignedValues)
{
return null;
}
return this.familyConfigurations;
}
set
{
this.familyConfigurations.Assign(value);
}
}
As far as I can tell, they seem to generate pretty much the same thing. However, with the latter code, the object and all of its references are correctly populated (FamilyConfigurations contains a non-null entry) on the server side of a WCF call, but by the time it gets to the client, FamilyConfigurations is null.
I’m assuming I have a serialization problem of some sort, but I don’t see what the difference between the two generated properties is. Perhaps there’s something else that needs to be done? The generated class of which FamilyConfigurations is a member has a DataContract tag under both generators.
Update: FamilyConfigurations is null, it is not a collection containing null, as previously state.
Has FamilyConfiguration changed? I have seen serialization break because of a changed parent-child relationship. Specifically, the child can not have an Association to its parent. That would be my first guess without being able to see the classes themselves.
EDIT: You can write a small console app that serializes and deserializes your objects using the DataContractSerializer explicitly to find out if serialization is the problem.