{"action":"created","issue":{"url":"https://api.github.com/repos/OData/WebApi/issues/1682","repository_url":"https://api.github.com/repos/OData/WebApi","labels_url":"https://api.github.com/repos/OData/WebApi/issues/1682/labels{/name}","comments_url":"https://api.github.com/repos/OData/WebApi/issues/1682/comments","events_url":"https://api.github.com/repos/OData/WebApi/issues/1682/events","html_url":"https://github.com/OData/WebApi/issues/1682","id":381145411,"node_id":"MDU6SXNzdWUzODExNDU0MTE=","number":1682,"title":"[feature/netcore] RouteAttribute causes AmbiguousActionException","user":{"login":"cornem","id":7910589,"node_id":"MDQ6VXNlcjc5MTA1ODk=","avatar_url":"https://avatars2.githubusercontent.com/u/7910589?v=4","gravatar_id":"","url":"https://api.github.com/users/cornem","html_url":"https://github.com/cornem","followers_url":"https://api.github.com/users/cornem/followers","following_url":"https://api.github.com/users/cornem/following{/other_user}","gists_url":"https://api.github.com/users/cornem/gists{/gist_id}","starred_url":"https://api.github.com/users/cornem/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cornem/subscriptions","organizations_url":"https://api.github.com/users/cornem/orgs","repos_url":"https://api.github.com/users/cornem/repos","events_url":"https://api.github.com/users/cornem/events{/privacy}","received_events_url":"https://api.github.com/users/cornem/received_events","type":"User","site_admin":false},"labels":[{"id":614080880,"node_id":"MDU6TGFiZWw2MTQwODA4ODA=","url":"https://api.github.com/repos/OData/WebApi/labels/question","name":"question","color":"fef2c0","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-11-15T12:45:22Z","updated_at":"2018-11-16T09:03:08Z","closed_at":null,"author_association":"NONE","body":"<!-- markdownlint-disable MD002 MD041 -->\r\n\r\nI am adding OData actions to an existing API. I want the OData-enabled endpoint to be available under the same route as my existing actions. My controller was available under `/api/salesorders`. I have changed the controller so it now inherits from `ODataController`. I have added these actions:\r\n````\r\npublic SalesOrdersController : ODataController\r\n{\r\n    [EnableQuery]\r\n    public IQueryable<SalesOrder> Get()\r\n    {\r\n        return _context.SalesOrders;\r\n    }\r\n\r\n    [EnableQuery]\r\n    public SalesOrder Get(int key)\r\n    {\r\n        return _context.SalesOrders.Find(key);\r\n    }\r\n}\r\n````\r\n\r\nIn my `Startup` class, I have registered OData:\r\n\r\n    app.UseMvc(routes =>\r\n    {\r\n        routes.Select().Expand().Filter().OrderBy().MaxTop(100).Count();\r\n        routes.MapODataServiceRoute(\"odata\", \"api\", GetEdmModel());\r\n    });\r\n\r\nThis works while there is no controller-level `RouteAttribute` specified. If I add `[Route(\"api/salesorders\")]` to the controller (for the benefit of my non-OData actions), the request `GET /api/salesorders` will fail with an `AmbiguousActionException`. (It now considers the `Get()` and `Get(int key)` as ambiguous. Note that `GET /api/salesorders(1)` will still succeed.)\r\n\r\nAdding additional `[HttpGet]` or `[ODataRoute]` attributes on the `Get()` and `Get(int key)` actions makes no difference.\r\n\r\n### Assemblies affected\r\n\r\nMicrosoft.AspNetCore.OData 7.0.1\r\n\r\n### Reproduce steps\r\n\r\n- Create a new ASP.NET Core project\r\n- Configure OData\r\n- Add an OData controller with a `Get()` and `Get(int key)` method\r\n- Add `[Route(\"someroute\")]` to the controller\r\n- Try to access the `Get()` action\r\n\r\n### Expected result\r\n\r\nThe `Get()` action method should be executed.\r\n\r\n### Actual result\r\n\r\nThe request fails with an `AmbiguousActionException`.\r\n"},"comment":{"url":"https://api.github.com/repos/OData/WebApi/issues/comments/439327130","html_url":"https://github.com/OData/WebApi/issues/1682#issuecomment-439327130","issue_url":"https://api.github.com/repos/OData/WebApi/issues/1682","id":439327130,"node_id":"MDEyOklzc3VlQ29tbWVudDQzOTMyNzEzMA==","user":{"login":"cornem","id":7910589,"node_id":"MDQ6VXNlcjc5MTA1ODk=","avatar_url":"https://avatars2.githubusercontent.com/u/7910589?v=4","gravatar_id":"","url":"https://api.github.com/users/cornem","html_url":"https://github.com/cornem","followers_url":"https://api.github.com/users/cornem/followers","following_url":"https://api.github.com/users/cornem/following{/other_user}","gists_url":"https://api.github.com/users/cornem/gists{/gist_id}","starred_url":"https://api.github.com/users/cornem/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cornem/subscriptions","organizations_url":"https://api.github.com/users/cornem/orgs","repos_url":"https://api.github.com/users/cornem/repos","events_url":"https://api.github.com/users/cornem/events{/privacy}","received_events_url":"https://api.github.com/users/cornem/received_events","type":"User","site_admin":false},"created_at":"2018-11-16T09:03:08Z","updated_at":"2018-11-16T09:03:08Z","author_association":"NONE","body":"@raheph I'm at a loss as to how I should use it then. I have tried the following (just to be clear, the controller has this attribute: '[Route(\"api/salesorders\")]`):\r\n\r\n```\r\n[EnableQuery, ODataRoute]\r\npublic IQueryable<SalesOrder> Get()             // AmbiguousActionException\r\n\r\n[EnableQuery, ODataRoute]\r\npublic SalesOrder Get(int key)                  // Works\r\n```\r\n```\r\n[EnableQuery, ODataRoute(RouteName = \"odata\")]\r\npublic IQueryable<SalesOrder> Get()             // AmbiguousActionException\r\n\r\n[EnableQuery, ODataRoute(RouteName = \"odata\")]\r\npublic SalesOrder Get(int key)                  // Works\r\n```\r\n```\r\n[EnableQuery, ODataRoute(\"SalesOrders\")]\r\npublic IQueryable<SalesOrder> Get()             // AmbiguousActionException\r\n\r\n[EnableQuery, ODataRoute(\"SalesOrders({key})\")]\r\npublic SalesOrder Get(int key)                  // Works\r\n```\r\n```\r\n[EnableQuery, ODataRoute(\"api/SalesOrders\")]\r\npublic IQueryable<SalesOrder> Get()             // AmbiguousActionException\r\n\r\n[EnableQuery, ODataRoute(\"api/SalesOrders({key})\")]\r\npublic SalesOrder Get(int key)                  // InvalidOperationException\r\n```\r\n\r\nSo how should `[ODataRoute]` be applied when using `[Route]` on the controller?\r\nAs a temporary fix, I can make everything work by removing `[Route]` from the controller, and adding attributes to my non-OData actions.\r\n\r\nHowever, it would be great if OData wouldn't break when using controller-level attribute routing."}}
{"actor":{"display_login":"cornem"}}