I am using the System.Web.Script.Serialization.JavaScriptSerializer contained in the System.Web.Extentions DLL. I have several circular links, such as a basic many-to-many relationship and a parent-child relationship. How can I deal with them? One of our ideas was to replace references to actual objects with foreign keys. For example, instead:
public class Node { public Node Parent { get; set; } public ICollection<Node> Children { get; set; } }
We would do this:
public class Node { public long ParentID { get; set; } public ICollection<long> ChildrenIDs { get; set; } }
I was thinking about using the ScriptIgnore attribute, but how do you use it using many-to-many relationships? Consultations and suggestions will be appreciated. Thanks!
Edit: Here are some examples of classes for many-to-many relationships.
public class Student { public long StudentID { get; private set; } public ICollection<Class> Classes { get; set; } } public class Class { public long ClassID { get; private set; } public ICollection<Student> Students { get; set; } }
source share