locked
Adding Child to an exisisting parent in Webapi odata controller using EF6 RRS feed

  • Question

  • User304970501 posted

    I using Odata Webapi with EF6 and my models are as below


    public class Company
    {

    Public Company()
    {
    Products = new List<Product>();

    }
    [Key]
    public int Id { get; set; }

    [Required]
    public string Name { get; set; }

    public List<Product> Products { get; set; }
    }
    public class Product
    {
    [Key]
    public int Id { get; set; }

    [Required]
    public string Name { get; set; }

    }

    I need to expose an end point to add product/s to an existing Company.
    the end point has to be something like below.

    Post: ~odata/Company(1)/Products with body as List of products json.
    body:[{"Name":"Product1"},{"Name":"Product2"}]

    Please suggest.

    Thanks for any help

    Friday, January 20, 2017 3:44 AM

All replies