Getting related entities ASP.NET WebApi OData v4 results in “No HTTP resource was found that matches the request URI”

前端 未结 2 1041
猫巷女王i
猫巷女王i 2021-01-02 09:02

I followed this asp.net tutorial by Mike Wasson, and managed to set up the related entities just fine, but when I applied this logic to my project the more complex entity re

2条回答
  •  别那么骄傲
    2021-01-02 09:55

    I am using ASP.NET 5, Web API 2.2, and Entity Framework.

    Another developer and I have also spent hours trying to figure out why, after following that same tutorial to a T, we couldn't get a relational route like the following to return anything other than a 404:

    /odata/Supplier(1)/Products
    

    We also tried the route debugger referenced in the OP, and it failed to produce anything other than a blank screen.

    Luckily, for our needs, one of our random experiments worked, and that was to use the ODataRoute attribute like such:

        [EnableQuery]
        [ODataRoute("Suppliers({key})/Products")]
        public IQueryable GetProductsForSupplier([FromODataUri] int key)
        {
            ...
        }
    

提交回复
热议问题