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 just 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).
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…