views:

129

answers:

2

In my project we serialize disconnected Linq-to-sql entities(mainly to preserve them between postbacks). Code in use for that is fairly straightforward:

        public static string Serialize<P>(this P entity)
        {
             StringWriter writer = new StringWriter();
             XmlTextWriter xmlWriter = new XmlTextWriter(writer);
             DataContractSerializer serializer = new DataContractSerializer(typeof(P));
             serializer.WriteObject(xmlWriter, entity);
             return writer.ToString();
        }

It works fine but after deserialization all EntityRef's children for that object are gone and replaced with just a foreign key value. Looks like this problem is due to the lack of bi-directional serialization. Is there existing work around for this problem?

A: 

Try changing the Serialization Mode property to "Unidirectional" on the Linq2Sql Dbml file. I ran into this issue when using L2S in a web service.

Tacoman667
That is what we currently using - "Unidirectional"
Victor
Any other ideas?
Victor
A: 

Looks like there is no answer for this question so just closing it for now

Victor