views:

126

answers:

1

I have two classes, which have one to many relation between them.

When I use s#arp to return lists of these tow classes, everything is ok.

But after I try to convert these two lists to Json format, I get a "circular reference" exception.

I have search this kind of exception on the web, and find it is an common question.

So, may I ask for some solutions to get rid of the exception in s#arp architecture? Thank you.

A: 

How do you "use S#arp" to return json? With "return Json(list)"? Then it's about ASP.NET/MVC only, no S#arp business here, and you better add "asp.net mvc" tag to the question to get more people answering you.

As for the problem, here are two possible solutions:

  • System.Web.Script.Serialization.ScriptIgnoreAttribute on either Parent property or ChildItems collection
  • mapping to list of another class, e.g. (from c in list select new TmpItem(c.Id, c.Name)).

But I can't tell for sure without seeing actual classes and without even knowing what do you use to convert lists to json.

queen3