Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9234485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:48:03+00:00 2026-06-18T06:48:03+00:00

Give the classes: public class Parent { public int id {get; set;} public int

  • 0

Give the classes:

public class Parent
{
    public int id {get; set;}
    public int name {get; set;}

    public virtual ICollection<Child> children {get; set;}
}

[Table("Child")]
public partial class Child
{
    [Key]
    public int id {get; set;}
    public string name { get; set; }

    [NotMapped]
    public string nickName { get; set; }
}

And the controller code:

List<Parent> parents = parentRepository.Get();
return Json(parents); 

It works on LOCALHOST, but it does not work on live server:

ERROR : Json A circular reference was detected while serializing an object of type

I did a search and found the [ScriptIgnore] attribute, so I changed the model to

using System.Web.Script.Serialization;

public class Parent
{
    public int id {get; set;}
    public int name {get; set;}

    [ScriptIgnore]
    public virtual ICollection<Child> children {get; set;}
}

But the same error occur on live server (win2008).

How can I avoid that error and serialize the parent data successfully?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T06:48:05+00:00Added an answer on June 18, 2026 at 6:48 am

    Try the following code:

    return Json(
        parents.Select(x => new {
            id = x.id,
            name = x.name,
            children = x.children.Select(y => new {
                // Assigment of child fields
            })
        })); 
    

    …or if you only need the parent properties:

    return Json(
        parents.Select(x => new {
            id = x.id,
            name = x.name
        })); 
    

    It is not really the solution for the problem, but it is a common workaround when serializing DTOs…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two entity classes: public class Invoice { public int ID { get;
Assume the following entity classes: public class Player { public virtual int ID {
I have the following classes: public class Note { public string Text { get;
In my code my child classes are not picking up my parent class for
To give an idea of my requirement, consider these classes - class A {
When exactly does the compiler create a virtual function table? 1) when the class
Consider following Java classes: public class Animal { public static void printText(Object obj) {
Say I have the following classes public class TestA { public string Blah {
I have the following classes: public class Layer { public Tile[,] Grid; //50x50 positions
I have those classes, an implementation of active record pattern: public abstract class RecordCollection<T>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.