开发者

NHibernate and WCF Serialization(Unidirectional)

Object graph for type '[type]' contains cycles and cannot be serialized if reference tracking is disabled.

I have a simple class hierarchy setup using NHibernate as my persistence layer.

For example:

public class Parent
{
    public virtual IList<Child> Children{get;set;}
}

public class Child
{
    public virtual Parent Parent{get;set;}
}

This is ju开发者_开发知识库st done to relate a Child to a single parent and is persisted via foreign key in the database. The NHibernate part and persistence works just fine. The issue occurs when exposing this relationship via WCF web service. I realize there is a cyclical reference here and have read a few solutions for LINQ to SQL allowing for unidirectional serialization, however am unable to find a solution when not using a dbml file.

UPDATE

An additional question would be, is it common practice to abstract a set of DTO's to expose via web service as opposed to the original entities? This would solve the serialization issue as the DTO classes would not necessarily need cyclic references(as they are not NHibernate entities).

Additional Update

I came across an article that may be in the right direction. I'm testing this out currently and will post if successful(for article worth's sake).


It is best practice to protect your domain and not let it go across process boundaries. I would recommend a DTO implementation to abstract your domain. There are other benefits as well including that you can provide an intention revealing interface(clients shouldn't have to think about how to use the service).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜