You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using a DateTime property as part of an aggregate transformation an exception is thrown. Pull request #2302 fixes the same issue but just when the property is used inside a groupby transformation.
/SomeEntitySet?$apply=aggregate(SomeDateTimeProperty with min as MinDateTime)
/SomeEntitySet?$apply=groupby((SomeProperty), aggregate(SomeDateTimeProperty with min as MinDateTime))
Expected result
No exception is thrown
Actual result
message: "An ODataPrimitiveValue was instantiated with a value of type 'System.DateTime'. ODataPrimitiveValue can only wrap values which can be represented as primitive EDM types.",
stacktrace: "
at Microsoft.OData.ODataPrimitiveValue..ctor(Object value) in ...\Microsoft.OData.Core\Value\ODataPrimitiveValue.cs:line 34
at Microsoft.OData.ODataValueUtils.ToODataValue(Object objectToConvert) in ...\Microsoft.OData.Core\Value\ODataValueUtils.cs:line 49
at Microsoft.OData.ODataProperty.set_Value(Object value) in ...\Microsoft.OData.Core\ODataProperty.cs:line 30
at Microsoft.AspNet.OData.Formatter.Serialization.ODataResourceSerializer.CreateODataPropertiesFromDynamicType(EdmEntityType entityType, Object graph, Dictionary`2 dynamicTypeProperties) in ...\Microsoft.AspNet.OData.Shared\Formatter\Serialization\ODataResourceSerializer.cs:line 1282
at Microsoft.AspNet.OData.Formatter.Serialization.ODataResourceSerializer.WriteDynamicTypeResource(Object graph, ODataWriter writer, IEdmTypeReference expectedType, ODataSerializerContext writeContext) in ...\Microsoft.AspNet.OData.Shared\Formatter\Serialization\ODataResourceSerializer.cs:line 1302
at Microsoft.AspNet.OData.Formatter.Serialization.ODataResourceSerializer.WriteResource(Object graph, ODataWriter writer, ODataSerializerContext writeContext, IEdmTypeReference expectedType) in ...\Microsoft.AspNet.OData.Shared\Formatter\Serialization\ODataResourceSerializer.cs:line 1392
at Microsoft.AspNet.OData.Formatter.Serialization.ODataResourceSerializer.WriteObjectInline(Object graph, IEdmTypeReference expectedType, ODataWriter writer, ODataSerializerContext writeContext) in ...\Microsoft.AspNet.OData.Shared\Formatter\Serialization\ODataResourceSerializer.cs:line 104
at Microsoft.AspNet.OData.Formatter.Serialization.ODataResourceSetSerializer.WriteResourceSet(IEnumerable enumerable, IEdmTypeReference resourceSetType, ODataWriter writer, ODataSerializerContext writeContext) in ...\Microsoft.AspNet.OData.Shared\Formatter\Serialization\ODataResourceSetSerializer.cs:line 192
at Microsoft.AspNet.OData.Formatter.Serialization.ODataResourceSetSerializer.WriteObjectInline(Object graph, IEdmTypeReference expectedType, ODataWriter writer, ODataSerializerContext writeContext) in ...\Microsoft.AspNet.OData.Shared\Formatter\Serialization\ODataResourceSetSerializer.cs:line 117
at Microsoft.AspNet.OData.Formatter.Serialization.ODataResourceSetSerializer.WriteObject(Object graph, Type type, ODataMessageWriter messageWriter, ODataSerializerContext writeContext) in ...\Microsoft.AspNet.OData.Shared\Formatter\Serialization\ODataResourceSetSerializer.cs:line 62
at Microsoft.AspNet.OData.Formatter.ODataOutputFormatterHelper.WriteToStream(Type type, Object value, IEdmModel model, ODataVersion version, Uri baseAddress, MediaTypeHeaderValue contentType, IWebApiUrlHelper internaUrlHelper, IWebApiRequestMessage internalRequest, IWebApiHeaders internalRequestHeaders, Func`2 getODataMessageWrapper, Func`2 getEdmTypeSerializer, Func`2 getODataPayloadSerializer, Func`1 getODataSerializerContext) in ...\Microsoft.AspNet.OData.Shared\Formatter\ODataOutputFormatterHelper.cs:line 230
at Microsoft.AspNet.OData.Formatter.ODataMediaTypeFormatter.WriteToStreamAsync(Type type, Object value, Stream writeStream, HttpContent content, TransportContext transportContext, CancellationToken cancellationToken) in ...\Microsoft.AspNet.OData\Formatter\ODataMediaTypeFormatter.cs:line 329
Additional detail
The above mentioned pull request added conversion only when a edmProperty is found, and when using aggregate transformation seems like that is not the case:
Maybe it shouldn't matter if there is an edmProperty and always do the conversion or the aliased property should take the same type as the property which is being aggregated?
Based on how the edmProperty inside that method is retrived from the entityType.Properties I found a workaround where the alias has the same name as the property that is being aggregated on, which works, but maybe it shouldn't :D
/SomeEntitySet?$apply=aggregate(SomeDateTimeProperty with min as SomeDateTimeProperty)
Thanks!
The text was updated successfully, but these errors were encountered:
When using a DateTime property as part of an aggregate transformation an exception is thrown. Pull request #2302 fixes the same issue but just when the property is used inside a groupby transformation.
Assemblies affected
Microsoft.AspNet.OData 7.6.5
Microsoft.OData.Core 7.14.0
Microsoft.OData.Edm 7.14.0
Reproduce steps
/SomeEntitySet?$apply=aggregate(SomeDateTimeProperty with min as MinDateTime)
/SomeEntitySet?$apply=groupby((SomeProperty), aggregate(SomeDateTimeProperty with min as MinDateTime))
Expected result
No exception is thrown
Actual result
Additional detail
The above mentioned pull request added conversion only when a
edmProperty
is found, and when using aggregate transformation seems like that is not the case:WebApi/src/Microsoft.AspNet.OData.Shared/Formatter/Serialization/ODataResourceSerializer.cs
Lines 1272 to 1287 in 07cdc77
Maybe it shouldn't matter if there is an
edmProperty
and always do the conversion or the aliased property should take the same type as the property which is being aggregated?Based on how the
edmProperty
inside that method is retrived from theentityType.Properties
I found a workaround where the alias has the same name as the property that is being aggregated on, which works, but maybe it shouldn't :D/SomeEntitySet?$apply=aggregate(SomeDateTimeProperty with min as SomeDateTimeProperty)
Thanks!
The text was updated successfully, but these errors were encountered: