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

Sorting on a grouped nested dynamic property fails #1243

Open
clemvnt opened this issue May 24, 2024 · 0 comments
Open

Sorting on a grouped nested dynamic property fails #1243

clemvnt opened this issue May 24, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@clemvnt
Copy link

clemvnt commented May 24, 2024

Hello,

I have a case where I want to sort on a grouped nested dynamic property.

However, the request fails and I get an exception.

Assemblies affected

Microsoft.AspNetCore.OData 8.2.5

Reproduce steps

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

Actual result

  1. /customers => OK
  2. /customers?$apply=groupby((Address/City)) => OK
[
    { "Address": { "City": "City 2" } },
    { "Address": { "City": "City 1" } }
]
  1. /customers?$apply=groupby((Address/City))&$orderby=((Address/City)) => OK
[
    { "Address": { "City": "City 1" } },
    { "Address": { "City": "City 2" } }
]
  1. /customers?$apply=groupby((Address/DynamicCity)) => OK
[
    { "Address": { "DynamicCity": "City 2" } },
    { "Address": { "DynamicCity": "City 1" } }
]
  1. /customers?$apply=groupby((Address/DynamicCity))&$orderby=((Address/DynamicCity)) => NOK
System.ArgumentException: Instance property 'DynamicCity' is not defined for type 'Microsoft.AspNetCore.OData.Query.Wrapper.GroupByWrapper' (Parameter 'propertyName')
   at System.Linq.Expressions.Expression.Property(Expression expression, String propertyName)
   at Microsoft.AspNetCore.OData.Query.Expressions.QueryBinder.BindDynamicPropertyAccessQueryNode(SingleValueOpenPropertyAccessNode openNode, QueryBinderContext context)
   at Microsoft.AspNetCore.OData.Query.Expressions.QueryBinder.BindSingleValueNode(SingleValueNode node, QueryBinderContext context)
   at Microsoft.AspNetCore.OData.Query.Expressions.QueryBinder.Bind(QueryNode node, QueryBinderContext context)
   at Microsoft.AspNetCore.OData.Query.Expressions.OrderByBinder.BindOrderBy(OrderByClause orderByClause, QueryBinderContext context)
   at Microsoft.AspNetCore.OData.Query.Expressions.BinderExtensions.ApplyBind(IOrderByBinder binder, IQueryable query, OrderByClause orderByClause, QueryBinderContext context, Boolean alreadyOrdered)
   at Microsoft.AspNetCore.OData.Query.OrderByQueryOption.AddOrderByQueryForProperty(IOrderByBinder orderByBinder, OrderByClause orderbyClause, IQueryable querySoFar, QueryBinderContext binderContext, Boolean alreadyOrdered)
   at Microsoft.AspNetCore.OData.Query.OrderByQueryOption.ApplyToCore(IQueryable query, ODataQuerySettings querySettings)
   at Microsoft.AspNetCore.OData.Query.OrderByQueryOption.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)
   at Microsoft.AspNetCore.OData.Query.EnableQueryAttribute.OnActionExecuted(ActionExecutedContext actionExecutedContext)
   at Microsoft.AspNetCore.Mvc.Filters.ActionFilterAttribute.OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)

Expected result

I would expect the following result for the fifth query :

[
    { "Address": { "DynamicCity": "City 1" } },
    { "Address": { "DynamicCity": "City 2" } }
]
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