Search code examples
c#asp.net-coreodataodata-v4

OData Endpoint missing properties of the Entity


I have a class such as this

    public class AppData
    {
        [Key]
        [JsonProperty("Id")]
        public Guid AppId { get; set; }

        [JsonProperty("Link")]
        public string Link { get; set; }

        [JsonProperty("Products")]
        public List<Product> Products { get; set; }

    }


builder.EntitySet<AppData>("AppData");

When I hit this Odata endpoint the Products property is always missing, I can retrieve the AppId and Link no problem.

I can see on similar exmaples on stackoverflow such as this, OData Endpoint doesn't return all properties of the Entity However, my Product type is already being used as a EntitySet, changing it to a complex type breaks other API's currently tied to it. Is it possible to have an entityset containing entitysets and return all the data properly?


Solution

  • we have a tutorial here, which showed us to have code below in Program.cs

    modelBuilder.EntityType<Order>();
    modelBuilder.EntitySet<Customer>("Customers");
    

    Then I had a test like below. I also tried to set modelBuilder.EntitySet<Order>("Orders"); and it worked as well.

    enter image description here