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 8858723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:53:34+00:00 2026-06-14T14:53:34+00:00

So I created a WebApi project in MVC4 and was having trouble understanding the

  • 0

So I created a WebApi project in MVC4 and was having trouble understanding the JSON output. I’m not entirely sure if this is the intended output of JSON or if i have done something incorrectly.

I have three tables, (pb_Project, pb_Tasks and pb_Priority). The relationship are as follows:
Project may have many tasks, and Each project can have one priority level.

entities http://img705.imageshack.us/img705/9294/stackoverflowentities.png

Now, the output that I am receiving is quite odd and not really intuitive. I’m not sure if this is the intended JSON (as I am brand new to it). When I run the website to retrieve the JSON output for the projects I get the following result.

[

    {
        "$id": "1",
        "pb_Priority": {
            "$id": "2",
            "pb_Projects": [
                {
                    "$ref": "1"
                },
                {
                    "$id": "3",
                    "pb_Priority": {
                        "$ref": "2"
                    },
                    "pb_Tasks": [
                        {
                            "$id": "4",
                            "pb_Projects": {
                                "$ref": "3"
                            },
                            "TASK_ID": 3,
                            "PROJECT_ID": 2,
                            "USER_ID": 2,
                            "DUE_DATE": "2012-11-19T00:00:00",
                            "PRIORITY_ID": 2,
                            "TASK_NAME": "project 2 task 1",
                            "DESCRIPTION": "asdf"
                        }
                    ],
                    "PROJECT_ID": 2,
                    "USER_ID": 2,
                    "NAME": "Project2",
                    "DESCRIPTION": "project 2 description",
                    "BUDGET": 1,
                    "LOCATION": "CANADA",
                    "START_DATE": "2012-11-18T00:00:00",
                    "PRIORITY_ID": 1,
                    "PROJ_SCALE": null,
                    "NOTES": null
                }
            ],
            "PRIORITY_ID": 1,
            "PRIORITY_LEVEL": 1
        },
        "pb_Tasks": [
            {
                "$id": "5",
                "pb_Projects": {
                    "$ref": "1"
                },
                "TASK_ID": 1,
                "PROJECT_ID": 1,
                "USER_ID": 1,
                "DUE_DATE": "2012-11-19T00:00:00",
                "PRIORITY_ID": 1,
                "TASK_NAME": "project 1 task 1",
                "DESCRIPTION": "adsf"
            },
            {
                "$id": "6",
                "pb_Projects": {
                    "$ref": "1"
                },
                "TASK_ID": 2,
                "PROJECT_ID": 1,
                "USER_ID": 2,
                "DUE_DATE": "2012-11-19T00:00:00",
                "PRIORITY_ID": 1,
                "TASK_NAME": "project 1 task 2 user 2",
                "DESCRIPTION": "asd"
            }
        ],
        "PROJECT_ID": 1,
        "USER_ID": 1,
        "NAME": "Project1",
        "DESCRIPTION": "project 1 description",
        "BUDGET": 1000,
        "LOCATION": "USA",
        "START_DATE": "2012-11-18T00:00:00",
        "PRIORITY_ID": 1,
        "PROJ_SCALE": null,
        "NOTES": null
    },
    {
        "$ref": "3"
    }

]

The controller for this is as follows:

public IEnumerable<pb_Projects> Getpb_Projects()
{
    return db.pb_Projects.AsEnumerable();
}

What I would expect from this json result would be a list of Projects(objects) with any other relative FK’s and such. Whereas here I get one big object, with another ref as the 2nd object. Am i doing something wrong, i would expect something like this (don’t worry its just test data so no real passwords :P)…

[

{
    "$id": "1",
    "UserId": 1,
    "CreateDate": "2012-11-18T21:46:56.78",
    "ConfirmationToken": null,
    "IsConfirmed": true,
    "LastPasswordFailureDate": null,
    "PasswordFailuresSinceLastSuccess": 0,
    "Password": "AIGvGbJIedgTyY+m08DCVhZbVnRTWzW6kvl1JMOqsFqOCSjnJTBlGUGmVveAYIONJw==",
    "PasswordChangedDate": "2012-11-18T21:46:56.78",
    "PasswordSalt": "",
    "PasswordVerificationToken": null,
    "PasswordVerificationTokenExpirationDate": null
},
{
    "$id": "2",
    "UserId": 2,
    "CreateDate": "2012-11-18T21:48:05.067",
    "ConfirmationToken": null,
    "IsConfirmed": true,
    "LastPasswordFailureDate": null,
    "PasswordFailuresSinceLastSuccess": 0,
    "Password": "ACeoUpOVNEvgumvmSkFziRkNQzTlZC8+KAy32egXQseKLmhmJGX/VDXRXylkBUph3Q==",
    "PasswordChangedDate": "2012-11-18T21:48:05.067",
    "PasswordSalt": "",
    "PasswordVerificationToken": null,
    "PasswordVerificationTokenExpirationDate": null
},
{
    "$id": "3",
    "UserId": 3,
    "CreateDate": "2012-11-19T00:35:49.163",
    "ConfirmationToken": null,
    "IsConfirmed": true,
    "LastPasswordFailureDate": null,
    "PasswordFailuresSinceLastSuccess": 0,
    "Password": "AF7W+1FNLcaA2qJ3nmrB7S9mkJmJGZCpAZYbyH5+iXryq1epr8i67ddgSbvFQF1bQw==",
    "PasswordChangedDate": "2012-11-19T00:35:49.163",
    "PasswordSalt": "",
    "PasswordVerificationToken": null,
    "PasswordVerificationTokenExpirationDate": null
},
{
    "$id": "4",
    "UserId": 4,
    "CreateDate": "2012-11-19T00:39:00.667",
    "ConfirmationToken": null,
    "IsConfirmed": true,
    "LastPasswordFailureDate": null,
    "PasswordFailuresSinceLastSuccess": 0,
    "Password": "ABPdfSj8jZAWqhHMDuTVQuL3AiEmiplSujA/GNjQoGoMQm0zhNwAAOaInbqrXFrM0g==",
    "PasswordChangedDate": "2012-11-19T00:39:00.667",
    "PasswordSalt": "",
    "PasswordVerificationToken": null,
    "PasswordVerificationTokenExpirationDate": null
}

]

Here is the raw unformatted JSON

[{"$id":"1","pb_Priority":{"$id":"2","pb_Projects":[{"$ref":"1"},{"$id":"3","pb_Priority":{"$ref":"2"},"pb_Tasks":[],"PROJECT_ID":2,"USER_ID":2,"NAME":"test2","DESCRIPTION":"test2","BUDGET":1.0,"LOCATION":"test","START_DATE":"2012-11-18T00:00:00","PRIORITY_ID":1,"PROJ_SCALE":null,"NOTES":null}],"PRIORITY_ID":1,"PRIORITY_LEVEL":1},"pb_Tasks":[{"$id":"4","pb_Projects":{"$ref":"1"},"TASK_ID":1,"PROJECT_ID":1,"USER_ID":1,"DUE_DATE":"2012-11-19T00:00:00","PRIORITY_ID":1,"TASK_NAME":"asdf","DESCRIPTION":"adsf"},{"$id":"5","pb_Projects":{"$ref":"1"},"TASK_ID":2,"PROJECT_ID":1,"USER_ID":2,"DUE_DATE":"2012-11-19T00:00:00","PRIORITY_ID":1,"TASK_NAME":"sdf","DESCRIPTION":"asd"},{"$id":"6","pb_Projects":{"$ref":"1"},"TASK_ID":3,"PROJECT_ID":1,"USER_ID":2,"DUE_DATE":"2012-11-19T00:00:00","PRIORITY_ID":2,"TASK_NAME":"dsf","DESCRIPTION":"asdf"}],"PROJECT_ID":1,"USER_ID":1,"NAME":"test","DESCRIPTION":"test","BUDGET":null,"LOCATION":"test","START_DATE":"2012-11-18T00:00:00","PRIORITY_ID":1,"PROJ_SCALE":null,"NOTES":null},{"$ref":"3"}]
  • 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-14T14:53:35+00:00Added an answer on June 14, 2026 at 2:53 pm

    If you are using EF, by default, it will lazy load all the data from navigation properties. When serializer serializes model, it will visit each property on your model and EF will load all nested data.

    As a best practice, you shouldn’t expose your DB model as web api model. You’d better create another DTO model which you can control exactly what will be returned to client and what you want to receive from client.

    Or you can quickly workaround it by hiding those navigation properties by modifier (mark them as internal), or using [IgnoreDataMember] attribute. It tells serializer not to visit them when serializing and deserilaizing.

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

Sidebar

Related Questions

Using ASP.NET MVC4 I have created a DelegatingHandler in a WebAPI project. I use
I've created a method using the new WebAPI features in MVC4 and have it
I have a project created in Eclipse that has roughly this structure: src conf
I'm having trouble with my project. I have 2 models class UserPrefs(db.Model): user =
I have a maven project created with maven-archetype-webapp. As i use on Windows machine,
I have created a project using the following maven webapp project in eclipse: When
I have created simple Java Dynamic Web project in Eclipse. I host my project
I have created a local Groovy project in Eclipse. I am now starting to
Using Eclipse Helios, I tried to start a JSF based project. After having created
I just created an ASP .NET MVC 4 WebAPI project. In looking at the

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.