Count with filter doesn't work in ODATA queries
According to ODATA v4 Spec Protocol Part
Section 11.2.5.1 System Query Option $filter
http://docs.oasis-open.org/odata/odata/v4.0/errata02/os/complete/part1-protocol/odata-v4.0-errata02-os-part1-protocol-complete.html#_Toc406398301
The following query is supported in ODATA
http://host/service/Categories?$filter=Products/$count lt 10
However when I try this against a Web API 2.2 with OData4, I am getting the following error:
"code":"","message":"The query specified in the URI is not valid. The parent value for a property access of a property '$count' is not a single value. Property access can only be applied to a single value.","innererror":{ "message":"The parent value for a property access of a property '$count' is not a single value. Property access can only be applied to a single value.","type":"Microsoft.OData.Core.ODataException","stacktrace":" at Microsoft.OData.Core.UriParser.Parsers.EndPathBinder.BindEndPath....
Is this the expected behavior?
I have the same issue.
Same here.
According to the OData 4 standard this should work. Any word on this?
Should work.. same here just not with filter but with orderby for my example:
http://localhost:60760/odata/CurrentlyAdmitted?$top=50&$orderby=admissionsLastYear/$count
getting:
{
"error":{
"code":"","message":"The query specified in the URI is not valid. The parent value for a property access of a property '$count' is not a single value. Property access can only be applied to a single value.","innererror":{
"message":"The parent value for a property access of a property '$count' is not a single value. Property access can only be applied to a single value.","type":"Microsoft.OData.Core.ODataException","stacktrace":" at Microsoft.OData.Core.UriParser.Parsers.EndPathBinder.BindEndPath(EndPathToken endPathToken)\r\n at Microsoft.OData.Core.UriParser.Parsers.MetadataBinder.BindEndPath(EndPathToken endPathToken)\r\n at Microsoft.OData.Core.UriParser.Parsers.MetadataBinder.Bind(QueryToken token)\r\n at Microsoft.OData.Core.UriParser.Parsers.OrderByBinder.ProcessSingleOrderBy(BindingState state, OrderByClause thenBy, OrderByToken orderByToken)\r\n at Microsoft.OData.Core.UriParser.Parsers.OrderByBinder.BindOrderBy(BindingState state, IEnumerable`1 orderByTokens)\r\n at Microsoft.OData.Core.UriParser.ODataQueryOptionParser.ParseOrderByImplementation(String orderBy, ODataUriParserConfiguration configuration, IEdmType elementType, IEdmNavigationSource navigationSource)\r\n at Microsoft.OData.Core.UriParser.ODataQueryOptionParser.ParseOrderBy()\r\n at System.Web.OData.Query.OrderByQueryOption.get_OrderByClause()\r\n at System.Web.OData.Query.Validators.OrderByQueryValidator.Validate(OrderByQueryOption orderByOption, ODataValidationSettings validationSettings)\r\n at System.Web.OData.Query.OrderByQueryOption.Validate(ODataValidationSettings validationSettings)\r\n at System.Web.OData.Query.Validators.ODataQueryValidator.Validate(ODataQueryOptions options, ODataValidationSettings validationSettings)\r\n at System.Web.OData.Query.ODataQueryOptions.Validate(ODataValidationSettings validationSettings)\r\n at System.Web.OData.EnableQueryAttribute.ValidateQuery(HttpRequestMessage request, ODataQueryOptions queryOptions)\r\n at System.Web.OData.EnableQueryAttribute.ExecuteQuery(Object response, HttpRequestMessage request, HttpActionDescriptor actionDescriptor)\r\n at System.Web.OData.EnableQueryAttribute.OnActionExecuted(HttpActionExecutedContext actionExecutedContext)"
}
}
}
It's issue in ODL parse.
Any news on this, or a workaround besides a custom function? I really want this: GET http://somedomain.com.au/odata/Programs?$filter=Sessions/$count+lte+MaxSessions
One more note, specification has a bug before, it is fixed in this link https://tools.oasis-open.org/version-control/browse/wsvn/odata/trunk/spec/ABNF/odata-abnf-construction-rules.txt?op=diff&rev=781
Which means orderby and filter based on complexColl/TypeCast/$count are supported too.
See odata lib commit: https://github.com/OData/odata.net/commit/1b58ec6cab8965e68b4a8639262583adbce04e22
ODL V6.15 will support this. So, Web API OData v5.10 can add it.
Related issue : https://github.com/OData/odata.net/issues/573
@AndriiKuznietsov @rpawlaszek @hollis21 @mikila85 @andrensairr would you help to review my PR #738 ?
Any progress on this issue?
Looks like this is not yet fixed though a very popular request.
I still see "message": "The method or operation is not implemented." for sample project. Is ODATA queries #194 fixed? https://services.odata.org/TripPinRESTierService/People?$orderby=Trips/$count
This is still an issue for me with Odata V4 - https://host/service?$filter=RowChangedDatetime gt 2021-06-30T15:59:57.0000000Z/$count
When I send the above on Postman I get
{
"error": {
"code": "",
"message": "The query specified in the URI is not valid. The DateTimeOffset text '2021-06-30T15:59:57.0000000Z/$count' should be in format 'yyyy-mm-ddThh:mm:ss('.'s+)?(zzzzzz)?' and each field value is within valid range.",
"details": [],
"innererror": {
"message": "The DateTimeOffset text '2021-06-30T15:59:57.0000000Z/$count' should be in format 'yyyy-mm-ddThh:mm:ss('.'s+)?(zzzzzz)?' and each field value is within valid range.",
"type": "Microsoft.OData.ODataException",
"stacktrace": " at Microsoft.OData.UriUtils.ConvertUriStringToDateTimeOffset(String text, DateTimeOffset& targetValue)\r\n at Microsoft.OData.UriParser.ExpressionLexer.TryParseDateTimeoffset(Int32 tokenPos)\r\n at Microsoft.OData.UriParser.ExpressionLexer.ParseFromDigit()\r\n at Microsoft.OData.UriParser.ExpressionLexer.NextTokenImplementation(Exception& error)\r\n at Microsoft.OData.UriParser.ExpressionLexer.NextToken()\r\n at Microsoft.OData.UriParser.UriQueryExpressionParser.ParseComparison()\r\n at Microsoft.OData.UriParser.UriQueryExpressionParser.ParseLogicalAnd()\r\n at Microsoft.OData.UriParser.UriQueryExpressionParser.ParseLogicalOr()\r\n at Microsoft.OData.UriParser.UriQueryExpressionParser.ParseExpression()\r\n at Microsoft.OData.UriParser.UriQueryExpressionParser.ParseExpressionText(String expressionText)\r\n at Microsoft.OData.UriParser.ODataQueryOptionParser.ParseFilterImplementation(String filter, ODataUriParserConfiguration configuration, ODataPathInfo odataPathInfo)\r\n at Microsoft.OData.UriParser.ODataQueryOptionParser.ParseFilter()\r\n at Microsoft.AspNet.OData.Query.FilterQueryOption.get_FilterClause()\r\n at Microsoft.AspNet.OData.Query.Validators.FilterQueryValidator.Validate(FilterQueryOption filterQueryOption, ODataValidationSettings settings)\r\n at Microsoft.AspNet.OData.Query.Validators.ODataQueryValidator.Validate(ODataQueryOptions options, ODataValidationSettings validationSettings)\r\n at Microsoft.AspNet.OData.EnableQueryAttribute.ValidateQuery(HttpRequest request, ODataQueryOptions queryOptions)\r\n at Microsoft.AspNet.OData.EnableQueryAttribute.<>c__DisplayClass1_0.<OnActionExecuted>b__1(ODataQueryContext queryContext)\r\n at Microsoft.AspNet.OData.EnableQueryAttribute.ExecuteQuery(Object responseValue, IQueryable singleResultCollection, IWebApiActionDescriptor actionDescriptor, Func2 modelFunction, IWebApiRequestMessage request, Func2 createQueryOptionFunction)\r\n at Microsoft.AspNet.OData.EnableQueryAttribute.OnActionExecuted(Object responseValue, IQueryable singleResultCollection, IWebApiActionDescriptor actionDescriptor, IWebApiRequestMessage request, Func2 modelFunction, Func2 createQueryOptionFunction, Action1 createResponseAction, Action3 createErrorAction)",
"internalexception": {
"message": "The string '2021-06-30T15:59:57.0000000Z/$count' is not a valid AllXsd value.",
"type": "System.FormatException",
"stacktrace": " at System.Xml.XmlConvert.ToDateTimeOffset(String s)\r\n at Microsoft.OData.PlatformHelper.ConvertStringToDateTimeOffset(String text)\r\n at Microsoft.OData.UriUtils.ConvertUriStringToDateTimeOffset(String text, DateTimeOffset& targetValue)"
}
}
}
}