-
Notifications
You must be signed in to change notification settings - Fork 178
Description
Assemblies affected
Microsoft.AspNetCore.OData 9.3.0
Describe the bug
Custom aggregate function e.g. $apply=aggregate(... with custom.stdev) over dynamic properties (open type dictionary fields) throws NullReferenceException during parsing. The options ODataQueryOptions.Apply.ApplyClause contains the exception as soon as the action is called.
I can verify that the declared properties work fine, and I've successfully parsed custom.stdev using following query, where filesize is part of the entity:
$apply=aggregate(filesize with custom.stdev as filesizedev)
However, when the aggregated field is a dynamic (open type) property, the parser fails.
$apply=aggregate(dynprop with custom.stdev as dynpropdev)
Interesting is, if I add dynprop to EdmModel like following then the parsing of ApplyClause works:
var edmEntityType = (EdmEntityType) model.FindDeclaredType(typeof(MyEntity).FullName);
edmEntityType.AddStructuralProperty("dynprop", EdmPrimitiveTypeKind.Double);
Unfortunately, I can't do that, as the properties are dynamic and depend on the data.
Is there a supported way to dynamically provide type information for open-type properties at runtime, before the ODataQueryOptions is prepared for controller action?
If not, is there a recommended approach or extension point to safely support this scenario?