Is there a workaround for lack of bi-directional serialization
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?
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.
精彩评论