Open athoscouto opened 7 years ago
Apparently, this is because when aggregation is done the ODataWriterCore
created has as the IEdmStructuredType resourceType
the type that's being aggregated.
This should not happen because the resulting type of the aggregation will not have the same structure that the aggregated model has.
Keeping the resourceType
of the serialization of aggregations as the model that's being aggregated impose a lot of checks that can lead to errors like this one.
Every aggregate query that uses as an alias the name of a property of the model being aggregated throws an ODataException if the types of the aggregated value and of the property don't match.
Assemblies affected
Which assemblies and versions are known to be affected e.g. OData .Net lib 6.15-beta.
Reproduce steps
I used the Northwind Database to reproduce the bug. A simple OData web app containing it can be found here. To create the error you just need to query the OData endpoint with an URL like:
{OData endpoint}/Orders/?$apply=aggregate(OrderID with countdistinct as Customer)
Expected result
Actual result
Additional details
This error is not specific to the aggregation method used, or if the one value is primitive and the other is non-primitive. If the aggregate property and the model property have the same name (alias) and their type differs, we'll get errors like this. Took a quick look at the spec and didn't find any restriction on aliases for aggregation properties.