0

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.

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

8 Comments

Well, in both instances, FmailyConfiguration has an association to Family, and they're pretty similar. Here's the SQL Metal FamilyConfiguration class: tinyurl.com/y8msxwv and here's the T4 class: tinyurl.com/y8p5kzd. I can post Family, too, if that'll help.
Here's the family code, as well. SQL Metal: tinyurl.com/y9kh4ta T4: tinyurl.com/yat2kyr
Do other properties on Family serialize correctly? And is the collection null or is it a collection of N null FamilyConfigurations?
You might try to write a small Console app that loads up a Family and then try to Serialize it using the DataContractSerializer explicitly. This might give you some insight into where the serialization might be failing.
I think it may actually be a serialization problem on the client side. Did you try to read the XML back in to objects using the DataContractSerializer? I grabbed your objects and was able to deserialize the SQL Metal objects but not the T4 objects. I got an Object Null Reference exception when it tried to read the set of FamilyConfiguration.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.