AspNetCoreOData icon indicating copy to clipboard operation
AspNetCoreOData copied to clipboard

How do I use the month function of date type in a group query

Open kingling-abb opened this issue 1 year ago • 4 comments

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

kingling-abb avatar Mar 26 '24 04:03 kingling-abb

Can also confirm this is broken, and would love it if it wasn't.

bbatchelder avatar Jul 03 '24 14:07 bbatchelder

Can you try something like this?

?compute=month(deliveryDate) as DeliveryMonth&apply=groupby(DeliveryMonth), aggregate($count as TotalCount))

julealgon avatar Jul 03 '24 14:07 julealgon

Can you try something like this?

?compute=month(deliveryDate) as DeliveryMonth&apply=groupby(DeliveryMonth), aggregate($count as TotalCount))

Yes, that's OK.

kingling-abb avatar Jul 04 '24 00:07 kingling-abb

@bbatchelder does my solution work for you as well?

julealgon avatar Jul 04 '24 15:07 julealgon