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-
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> { } }
}
None
0 Points
1 Post
No routing convention was found to select an action for the OData path with template '~/entityset...
Jul 27, 2015 01:10 PM|karanvohra|LINK
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:
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-
Can you kindly help me in understanding what am i doing wrong?
asp.net webapi
Member
30 Points
27 Posts
Re: No routing convention was found to select an action for the OData path with template '~/entit...
Jul 30, 2015 06:24 AM|progi|LINK
Show me your routing definitions and your web api configuration.
asp.net webapi
None
0 Points
1 Post
Re: No routing convention was found to select an action for the OData path with template '~/entit...
Aug 05, 2020 10:36 AM|NMurphy|LINK
Hi,
In your data model, does Customers have a navigation property pointing to Vendors? So your customer class should look something like
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: