Hi,
I'm building an OData v4 service with Web-Api 2.2. I have the following routes:
/Products
/Products('id') /Products('id')/Orders /Product('id')/Orders('id')
And I would like to have the following controllers/actions for them:
class ProductsController { [ODataRoute("/Products")] public IQueryable<Product> Get() {} [ODataRoute("/Products({id}")] public SingleResult<Product> Get(int id) {} } class OrdersController { [ODataRoute("/Orders")] public IQueryable<Order> Get() {} [ODataRoute("/Orders({id}")] public SingleResult<Order> Get(int id) {} [ODataRoute("/Products({id})/Orders")] public IQueryable<Order> GetByProduct(int productId) {} [ODataRoute("/Products({productId}/Orders({id})")] public SingleResult<Order> GetByProduct(int id, int productId) {} }
This is my config section in WebConfigApi.cs
ODataModelBuilder builder = new ODataConventionModelBuilder(); builder.EntitySet<Product>("Products"); builder.EntitySet<Order>("Orders"); var route = config.MapODataServiceRoute( routeName: "ODataRoute", routePrefix: null, model: builder.GetEdmModel());
But I'm getting errors about invalid OData routes. I was under the impression that when I use attribute routing I can use any action name and parameters that I like and I can organize my controllers/actions the way I want but that does not seem to be the
case. Are my assumptions wrong?
Thanks