AspNetCoreOData
AspNetCoreOData copied to clipboard
How do I use the month function of date type in a group query
Assemblies affected .NET 8.0 Microsoft.AspNetCore.OData 8.2.5
Describe the bug ?filter=month(deliveryDate) eq 3 is good working ?apply=groupby((month(deliveryDate)), aggregate($count as TotalCount)) Throw exception
Data Model public DateTime DeliveryDate { get; set; }
EDM (CSDL) Model <Property Name="deliveryDate" Type="Edm.DateTimeOffset" Nullable="false" />
Request/Response { "error": { "code": "", "message": "The query specified in the URI is not valid. Expression expected at position 28 in 'groupby((month(deliveryDate)), aggregate($count as TotalCount))'.", "details": [], "innererror": { "message": "Expression expected at position 28 in 'groupby((month(deliveryDate)), aggregate($count as TotalCount))'.", "type": "Microsoft.OData.ODataException", "stacktrace": " at Microsoft.OData.UriParser.UriQueryExpressionParser.ParseGroupBy()\r\n at Microsoft.OData.UriParser.UriQueryExpressionParser.ParseApply(String apply)\r\n at Microsoft.OData.UriParser.ODataQueryOptionParser.ParseApplyImplementation(String apply, ODataUriParserConfiguration configuration, ODataPathInfo odataPathInfo)\r\n at Microsoft.OData.UriParser.ODataQueryOptionParser.ParseApply()\r\n at Microsoft.AspNetCore.OData.Query.ApplyQueryOption.get_ApplyClause()\r\n at Microsoft.AspNetCore.OData.Query.Validator.ODataQueryValidator.Validate(ODataQueryOptions options, ODataValidationSettings validationSettings)\r\n at Microsoft.AspNetCore.OData.Query.ODataQueryOptions.Validate(ODataValidationSettings validationSettings)\r\n at Microsoft.AspNetCore.OData.Query.EnableQueryAttribute.ValidateQuery(HttpRequest request, ODataQueryOptions queryOptions)\r\n at Microsoft.AspNetCore.OData.Query.EnableQueryAttribute.OnActionExecuting(ActionExecutingContext actionExecutingContext)" } } }
Expected behavior We can figure out the quantity by month
Can also confirm this is broken, and would love it if it wasn't.
Can you try something like this?
?compute=month(deliveryDate) as DeliveryMonth&apply=groupby(DeliveryMonth), aggregate($count as TotalCount))
Can you try something like this?
?compute=month(deliveryDate) as DeliveryMonth&apply=groupby(DeliveryMonth), aggregate($count as TotalCount))
Yes, that's OK.
@bbatchelder does my solution work for you as well?