AspNetCoreOData icon indicating copy to clipboard operation
AspNetCoreOData copied to clipboard

$apply aggregation on nested collection not working or combined with Param $expand also not functioning

Open padhumailin opened this issue 3 years ago • 3 comments

Please check the repository (Sample Project) : https://github.com/padhumailin/ODataV8Demo

Parent entity Accounts has a collection property LinkedAccounts Entity, I need to apply aggregation on collection property

filter on collection is working: http://localhost:34987/api/accounts?$filter=LinkedAccounts/any(a:a/LinkedAccountName eq 'Loan1')

aggregation on parent entity also working: http://localhost:34987/api/accounts?$apply=groupby((AccountType), aggregate($count as total))

aggregation on collection property not working http://localhost:34987/api/accounts?$apply=groupby((LinkedAccounts/ParentId),%20aggregate($count%20as%20OrderCount))

http://localhost:34987/api/accounts?$expand=LinkedAccounts($apply=groupby((ParentId),%20aggregate($count%20as%20OrderCount)))

ERROR: {"error":{"code":"","message":"The query specified in the URI is not valid. The parent value for a property access of a property 'ParentId' is not a single value. Property access can only be applied to a single value.","details":[],"innererror":{"message":"The parent value for a property access of a property 'ParentId' is not a single value. Property access can only be applied to a single value.","type":"Microsoft.OData.ODataException"

Expected Result: [{"ParentId":"1","total":3},{"ParentId":"2","total":3},,{"ParentId":"3","total":3}]

Any suggestion on how to implement the EDM model or any diiferent way to write odata parameters to acheive

Environment: Net 6 OData 8.0.4

padhumailin avatar Feb 02 '22 07:02 padhumailin

Hi, @padhumailin

i've the same problem. do you known any solution ?

Good luck

adrua avatar May 20 '22 14:05 adrua

Same issue here on Odata 8.2.4, Entity Framework 8, and Net 8

Using groupby in $apply to get unique results with $expand collection property not working either

Esther-St avatar Apr 03 '24 19:04 Esther-St