Will Curran
Will Curran

Reputation: 7110

How to implement nested Models in ASP.NET Web API?

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?

Upvotes: 1

Views: 3612

Answers (2)

this.esty
this.esty

Reputation: 186

  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; }

        }

Upvotes: 0

DanielEli
DanielEli

Reputation: 3503

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; }
}

Upvotes: 1

Related Questions