开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜