{"action":"opened","issue":{"url":"https://api.github.com/repos/OData/WebApi/issues/862","repository_url":"https://api.github.com/repos/OData/WebApi","labels_url":"https://api.github.com/repos/OData/WebApi/issues/862/labels{/name}","comments_url":"https://api.github.com/repos/OData/WebApi/issues/862/comments","events_url":"https://api.github.com/repos/OData/WebApi/issues/862/events","html_url":"https://github.com/OData/WebApi/issues/862","id":192659023,"number":862,"title":"$top query option produces unexpected error when EnableQuery is used.","user":{"login":"jtcalhoun","id":9420,"avatar_url":"https://avatars.githubusercontent.com/u/9420?v=3","gravatar_id":"","url":"https://api.github.com/users/jtcalhoun","html_url":"https://github.com/jtcalhoun","followers_url":"https://api.github.com/users/jtcalhoun/followers","following_url":"https://api.github.com/users/jtcalhoun/following{/other_user}","gists_url":"https://api.github.com/users/jtcalhoun/gists{/gist_id}","starred_url":"https://api.github.com/users/jtcalhoun/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jtcalhoun/subscriptions","organizations_url":"https://api.github.com/users/jtcalhoun/orgs","repos_url":"https://api.github.com/users/jtcalhoun/repos","events_url":"https://api.github.com/users/jtcalhoun/events{/privacy}","received_events_url":"https://api.github.com/users/jtcalhoun/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-11-30T19:39:16Z","updated_at":"2016-11-30T19:39:16Z","closed_at":null,"body":"Attempting to use the `$top` query option in a controller action produces an `ODataException` with the message `\"The limit of '0' for Top query has been exceeded.\"` even when a `MaxTop` value has been specified in a [Controller Level Query Setting](http://odata.github.io/WebApi/#controller-level-query-setting).\r\n\r\n### Assemblies affected\r\nSystem.Web.OData, v6.0.0.0\r\n\r\n### Reproduce steps\r\n\r\n- Create an OData controller action that uses the `EnableQuery` attribute to specify that the `$top` query option is allowed with a `MaxTop` value. (see example below)\r\n- Navigate to the action using a `$top` value less than the `MaxTop` value specified.\r\n\r\n```\r\nnamespace MyApp\r\n{\r\n\t// using ...\r\n\t\r\n\tpublic class Product\r\n\t{\r\n\t\t[Key]\r\n\t\tpublic int Id { get; set; }\r\n\t}\r\n\t\r\n\t// Config...\r\n\t// var builder = ODataConventionModelBuilder();\r\n\t// builder.EntitySet<Product>(\"Products\");\r\n\t// config.MapODataServiceRoute(\"odata\", \"odata\", builder.GetEdmModel());\r\n\r\n\tpublic class ProductsController : ODataController\r\n\t{\r\n\t\t[EnableQuery(AllowedQueryOptions = AllowedQueryOptions.Top, MaxTop = 20)]\r\n\t\tpublic IEnumerable<Product> Get(ODataQueryOptions opts)\r\n\t\t{\r\n\t\t\tvar top = opts.Top != null ? opts.Top.Value : default(int);\r\n\t\t\treturn new[] { new Product { Id = top } };\r\n\t\t}\r\n\t}\r\n}\r\n```\r\n\r\n### Expected result\r\nThe action should return and OData response containing the number of entities specified by the `$top` query option.\r\n\r\n### Actual result\r\nWhen `$top` is a value from 1 to `MaxTop`, inclusive, an `ODataException` is thrown:\r\n\r\n> http://localhost/odata/Products?$top=1 (Using the example above.)\r\n>\r\n> Error message: \"The query specified in the URI is not valid. The limit of '0' for Top query has been exceeded. The value from the incoming request is '1'.\",\"innererror\":{\"message\":\"The limit of '0' for Top query has been exceeded. The value from the incoming request is '1'.\"\r\n\r\n### Additional details\r\n\r\nWhen `$top` is greater than `MaxTop`, the response is as expected:\r\n\r\n> http://localhost/odata/Products?$top=21\r\n> Error message: \"The query specified in the URI is not valid. The limit of '20' for Top query has been exceeded. The value from the incoming request is '21'.\",\"innererror\":{\"message\":\"The limit of '20' for Top query has been exceeded. The value from the incoming request is '21'.\"\r\n\r\nWhen `$top` is zero, the response is an empty array, as expected:\r\n\r\n> http://localhost/odata/Products?$top=0\r\n> Response: {\"@odata.context\":\"http://localhost/odata/$metadata#Products\",\"value\":[]}\r\n\r\n#### Possibly related: \r\n- #814 (The recommended solution (e.g. `config.MaxTop(20)`) enables `$top` for _all_ entities, which is not desired. Is requiring a global `MaxTop` value and enabling for all endpoints by design?)\r\n- #823 \r\n- https://github.com/OData/odata.net/issues/707\r\n"}}
{"actor":{"display_login":"jtcalhoun"}}