Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Group by a property of a derived type is not supported #1180

Open
clemvnt opened this issue Feb 29, 2024 · 4 comments
Open

Group by a property of a derived type is not supported #1180

clemvnt opened this issue Feb 29, 2024 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@clemvnt
Copy link

clemvnt commented Feb 29, 2024

Hello,

I have a case where I want to group by a property of a derived type :

/products?apply=groupby((category/ODataGroupByDerivedTypeIssue.Models.Category/categoryName)) 

An error indicating that this is not supported is thrown.

I would have expected it to be possible. Is it a lack or are there reasons why it's not possible?

Knowing that using a derived type in a filter clause works :

/products?filter=category/ODataGroupByDerivedTypeIssue.Models.Category/CategoryName eq 'Category 1'

Assemblies affected

Microsoft.AspNetCore.OData 8.2.4

Reproduce steps

  1. Clone the repository : https://github.com/clemvnt/ODataGroupByDerivedTypeIssue
  2. Run

It should open the /products?apply=groupby((category/ODataGroupByDerivedTypeIssue.Models.Category/categoryName)) URL.

Expected result

[
    { "category": { "categoryName": "Category 1" } },
    { "category": { "categoryName": "Category 2" } }
]

Actual result

The following error :

System.NotSupportedException: The query specified in the URI is not valid. Binding OData QueryNode of kind 'SingleResourceCast' is not supported by 'AggregationBinder'.

Stack trace :

at Microsoft.AspNetCore.OData.Query.Expressions.TransformationBinderBase.BindAccessor(QueryNode node, Expression baseElement)
at Microsoft.AspNetCore.OData.Query.Expressions.TransformationBinderBase.BindAccessor(QueryNode node, Expression baseElement)
at Microsoft.AspNetCore.OData.Query.Expressions.AggregationBinder.CreateGroupByMemberAssignments(IEnumerable`1 nodes)
at Microsoft.AspNetCore.OData.Query.Expressions.AggregationBinder.BindGroupBy(IQueryable query)
at Microsoft.AspNetCore.OData.Query.Expressions.AggregationBinder.Bind(IQueryable query)
at Microsoft.AspNetCore.OData.Query.ApplyQueryOption.ApplyTo(IQueryable query, ODataQuerySettings querySettings)
at Microsoft.AspNetCore.OData.Query.ODataQueryOptions.ApplyTo(IQueryable query, ODataQuerySettings querySettings)
at Microsoft.AspNetCore.OData.Query.EnableQueryAttribute.ApplyQuery(IQueryable queryable, ODataQueryOptions queryOptions)
at Microsoft.AspNetCore.OData.Query.EnableQueryAttribute.ExecuteQuery(Object responseValue, IQueryable singleResultCollection, ControllerActionDescriptor actionDescriptor, HttpRequest request)
at Microsoft.AspNetCore.OData.Query.EnableQueryAttribute.OnActionExecuted(ActionExecutedContext actionExecutedContext, Object responseValue, IQueryable singleResultCollection, ControllerActionDescriptor actionDescriptor, HttpRequest request)
@clemvnt clemvnt added the bug Something isn't working label Feb 29, 2024
@clemvnt
Copy link
Author

clemvnt commented Feb 29, 2024

I tried to look to support this case.

I succeeded by making the following changes:
clemvnt/odata.net@674ed16
clemvnt/AspNetCoreOData@45b7a57

Let me know if it sounds good. If so, I'll look into adding the tests.

@xuzhg
Copy link
Member

xuzhg commented Mar 1, 2024

I tried to look to support this case.

I succeeded by making the following changes: clemvnt/odata.net@674ed16 clemvnt/AspNetCoreOData@45b7a57

Let me know if it sounds good. If so, I'll look into adding the tests.

Thanks for your inputs. Both changes look good to me. Looking forward to your contribution by sharing us the complete Pull Request. Thanks

@clemvnt
Copy link
Author

clemvnt commented Mar 2, 2024

I have created both PRs :
OData/odata.net#2879
#1182

The second one is in draft because it depends on the first.

@corranrogue9
Copy link
Contributor

I will take the review of the ODL change, @xuzhg to work through the PR in this repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants