locked
No routing convention was found to select an action for the OData path with template '~/entityset/key/unresolved'.“,”type“:”“” RRS feed

  • Question

  • User-1538874048 posted

    In my ASP.Net Web API project, I have the following entities- Customer, Warehouse, SKU and Vendors. A customer can have multiple Warehouses, SKUs and Vendors. I have get methods in CustomersController to get the Warehouses by CustomerId or Vendors by Customer Id or SKUs by Customer Id. The following is the code in CustomersController.cs:

    [EnableQuery]
     public async Task<IHttpActionResult> GetSKUs([FromODataUri] long key)
    
    [EnableQuery]
    public async Task<IHttpActionResult> GetWarehouses([FromODataUri] long key) {}
    
     [EnableQuery]       
     public async Task<IHttpActionResult> GetVendors([FromODataUri] long key) {}

    The following URLs works - /BookMyLoad/Customers(10000)/Warehouses and /BookMyLoad/Customers(10000)/SKUs. The following URL gives a 404 error - /BookMyLoad/Customers(10000)/Vendors

    Detailed error is: { "error":{ "code":"","message":"No HTTP resource was found that matches the request URI 'http://localhost:62702/BookMyLoad/Customers(10000)/Vendors'.","innererror":{ "message":"No routing convention was found to select an action for the OData path with template '~/entityset/key/unresolved'.","type":"","stacktrace":"" } } }

    I have defined both Warehouses and Vendors properly-

        oDataModelBuilder.EntitySet<SKU>("SKUs");
            oDataModelBuilder.EntitySet<Warehouse>("Warehouses");
            oDataModelBuilder.EntitySet<Vendor>("Vendors");           
            oDataModelBuilder.EntitySet<Customer>("Customers");

    Can you kindly help me in understanding what am i doing wrong?

    Monday, July 27, 2015 1:10 PM

All replies

  • User2057898579 posted

    Show me your routing definitions and your web api configuration.

    Thursday, July 30, 2015 6:24 AM
  • User31626797 posted

    Hi,

    In your data model, does Customers have a navigation property pointing to Vendors? So your customer class should look something like 

    public class Customer {
        public int CustomerId
        ....
    
        public IEnumerable<Vendor> Vendors { get; set; }
        public IEnumerable<SKU> SKUs { get; set; }
        public IEnumerable<Warehouse> Warehouses { get; set; }
    }

    You need the navigation property to be defined on the entity in your data model before you can add it to the OData controller as a navigation property. You can even add a fake navigation property just to get the OData endpoint routing to work if you really need, although I wouldn't reccomend it: 

    public class Customer {
        public int CustomerId
        ....
    
        public IEnumerable<SKU> SKUs { get; set; }
        public IEnumerable<Warehouse> Warehouses { get; set; }
    
        public IEnumerable<Vendor> Vendors { get => return new List<Vendor> { } } 
    }

    Wednesday, August 5, 2020 10:36 AM