WebApi icon indicating copy to clipboard operation
WebApi copied to clipboard

$apply in combination with $select not working

Open wurst0815 opened this issue 7 years ago • 7 comments

Combination of $apply and $select not working. According to http://docs.oasis-open.org/odata/odata-data-aggregation-ext/v4.0/cs02/odata-data-aggregation-ext-v4.0-cs02.html#_Toc435016590

3.16 Evaluating $apply The new system query option $apply is evaluated first, then the other system query options are evaluated, if applicable, on the result of $apply in their normal order (see [OData-Protocol, section 11.2.1]). If the result is a collection, $filter, $orderby, $expand and $select work as usual on properties that are defined on the output set after evaluating $apply.

Assemblies affected

Microsoft.aspNet.OData 7.0.1.20718

Reproduce steps

RutHWModelsView?$apply=groupby((description,hw_model,id))&$select=description,hw_model,id

Expected result

The select should work as the groupby returns a collection.

Actual result

"message": "Instance property 'description' is not defined for type 'Microsoft.AspNet.OData.Query.Expressions.AggregationWrapper'",

Additional detail

Optional, details of the root cause if known. Delete this section if you have no additional details to add.

wurst0815 avatar Dec 03 '18 15:12 wurst0815

@kosinsky Would please take a look this issue?

xuzhg avatar Dec 05 '18 21:12 xuzhg

It's not implemented yet. Workaround is to just do "RutHWModelsView?$apply=groupby((description,hw_model,id))". Adding $select will not change query results

kosinsky avatar Dec 06 '18 00:12 kosinsky

That's correct, the result is the same in that case. But I'm using a framework which automatically adds the $select to the query, as it normally should work according to the specs. Is this already in scope for one of the next releases? Thanks

wurst0815 avatar Dec 06 '18 09:12 wurst0815

Is there any progress on this?

This is the stack trace I get when attempting a query which contains a groupby and a select

{
    "error": "System.ArgumentNullException",
    "message": "Value cannot be null.\r\nParameter name: property",
    "stackTrace": [
        "   at System.Linq.Expressions.Expression.Property(Expression expression, PropertyInfo property)\r",
        "   at Microsoft.AspNet.OData.Query.Expressions.SelectExpandBinder.CreatePropertyValueExpression(IEdmStructuredType elementType, IEdmProperty property, Expression source, FilterClause filterClause)\r",
        "   at Microsoft.AspNet.OData.Query.Expressions.SelectExpandBinder.BuildPropertyContainer(Expression source, IEdmStructuredType structuredType, IDictionary`2 propertiesToExpand, IDictionary`2 propertiesToInclude, ISet`1 autoSelectedProperties, Boolean isSelectingOpenTypeSegments)\r",
        "   at Microsoft.AspNet.OData.Query.Expressions.SelectExpandBinder.ProjectElement(Expression source, SelectExpandClause selectExpandClause, IEdmStructuredType structuredType, IEdmNavigationSource navigationSource)\r",
        "   at Microsoft.AspNet.OData.Query.Expressions.SelectExpandBinder.GetProjectionLambda(SelectExpandQueryOption selectExpandQuery)\r",
        "   at Microsoft.AspNet.OData.Query.Expressions.SelectExpandBinder.Bind(IQueryable queryable, SelectExpandQueryOption selectExpandQuery)\r",
        "   at Microsoft.AspNet.OData.Query.Expressions.SelectExpandBinder.Bind(IQueryable queryable, ODataQuerySettings settings, SelectExpandQueryOption selectExpandQuery)\r",
        "   at Microsoft.AspNet.OData.Query.SelectExpandQueryOption.ApplyTo(IQueryable queryable, ODataQuerySettings settings)\r",
        "   at Microsoft.AspNet.OData.Query.ODataQueryOptions.ApplySelectExpand[T](T entity, ODataQuerySettings querySettings)\r",
        "   at Microsoft.AspNet.OData.Query.ODataQueryOptions.ApplyTo(IQueryable query, ODataQuerySettings querySettings)\r",
        "   at Microsoft.AspNet.OData.EnableQueryAttribute.ApplyQuery(IQueryable queryable, ODataQueryOptions queryOptions)\r",
        "   at Microsoft.AspNet.OData.EnableQueryAttribute.ExecuteQuery(Object responseValue, IQueryable singleResultCollection, IWebApiActionDescriptor actionDescriptor, Func`2 modelFunction, IWebApiRequestMessage request, Func`2 createQueryOptionFunction)\r",
        "   at Microsoft.AspNet.OData.EnableQueryAttribute.OnActionExecuted(Object responseValue, IQueryable singleResultCollection, IWebApiActionDescriptor actionDescriptor, IWebApiRequestMessage request, Func`2 modelFunction, Func`2 createQueryOptionFunction, Action`1 createResponseAction, Action`3 createErrorAction)\r",
        "   at Microsoft.AspNet.OData.EnableQueryAttribute.OnActionExecuted(ActionExecutedContext actionExecutedContext)\r",
        "   at Microsoft.AspNetCore.Mvc.Filters.ActionFilterAttribute.OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)\r",
        "   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeNextActionFilterAsync()\r",
        "   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)\r",
        "   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)\r",
        "   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync()\r",
        "   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextExceptionFilterAsync()"
    ]
}

mikenorgate avatar Dec 12 '19 12:12 mikenorgate

Any updates on this? Will this be resolved, or do I need to find a work-around?

knapekt avatar Feb 13 '20 00:02 knapekt

Guys, any update on this in the latest version? If not, what is the work-around?

rjayabalan-conga avatar Jun 01 '20 06:06 rjayabalan-conga

same issue still there in Odata 8 , Net 6 , EF 6

padhumailin avatar Jan 25 '22 10:01 padhumailin