Home | Feedback | Login

Web API Nested Children or Master Detail

//This explains nested children call in web api.


using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Http; using System.Web.Http; using DataService.Models; using DataService.VM; namespace DataService.Controllers { public class ssController : ApiController { private SSEntities DB = null; public ssController() { DB = new SSEntities(); } public IEnumerable<CustomerVM> Get() { using (DB) { return DB.Customers .Include("CustomerAddress") .Include("CustomerAddressPhone") .Select( t => new CustomerVM { CustomerName = t.CustomerName, CustomerAddresses = t.CustomerAddresses.Select(p => new CustomerAddressVM { Address1 = p.Address1, CustomerAddressPhones = p.CustomerAddressPhones.Select(x => new CustomerAddressPhoneVM { LandLine = x.LandLine }) }) }).ToList(); } } } }