1

I cannot find a tutorial that shows how to implement a model that will manage hierarchical data.

For example how do I model:

{
  "name": "Joe Smith",
  "age": "40",
  "address": {
    "street": "123 pine",
    "city": "Redmond",
    "state": "WA"
  },

}

Where Address is a shared model?

2 Answers 2

1
public class Person
{
    public int PersonId { get; set; }
    public string Name { get; set; }
    public int Age { get; set; }
    public int AddressId { get; set; }
    public Address Address { get; set; }
}

public class Address
{
    public int AddressId { get; set; }
    public string Street { get; set; }
    public string City { get; set; }
}
Sign up to request clarification or add additional context in comments.

2 Comments

This is what I suspected - nothing surprising. But my JSON is flat, and not nested.
Oh wait, I am not setting AddressId but only the reference to Address.
0
  public class address
        {
            public String street { get; set; }
            public String city { get; set; }
            public String state { get; set; }
        }


        public class Employee
        {
            public String name { get; set; }
            public String age { get; set; }
            public address address { get; set; }

        }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.