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
Describe the bug
The BindSingleResourceCastFunctionCall() method links a "SingleResourceFunctionCallNode" to produce a LINQ "Expression" that signifies the meaning of the "SingleResourceFunctionCallNode".
This method takes two arguments: SingleResourceFunctionCallNode and QueryBinderContext. SingleResourceFunctionCallNode has a Parameters property, which is a list of QueryNodes.
The last QueryNode in this SingleResourceFunctionCallNode.Parameters parameter could be either of type ConstantNode or SingleResourceCastNode.
For instance:
/People?$orderby=cast(Location,NS.WorkAddress)/Company: The last query node in the SingleResourceFunctionCallNode.Parameters is of type SingleResourceCastNode. This occurs because NS.WorkAddress is bound as a DottedIdentifier and thus transformed into a SingleResourceCastNode.
/People?$orderby=cast(Location,'NS.WorkAddress')/Company: The last query node in the SingleResourceFunctionCallNode.Parameters is of type ConstantNode, as 'NS.WorkAddress' is bound as a Literal and consequently converted to ConstantNode.
/People?$filter=cast(Location,'NS.HomeAddress')/IsPrimaryResidence eq true: The last parameter is SingleResourceCastNode.
/People?$filter=cast(Location,NS.HomeAddress)/IsPrimaryResidence eq true: The last parameter is ConstantNode.
etc.
We should be able to cast the parameter as either SingleResourceCastNode or ConstantNode in order to enable the solution for this other issue OData/odata.net#1744
Reproduce steps
This issue was identified while fixing another issue OData/odata.net#1744
Expected behavior cast with quoted and unquoted type param should return the same data. For example cast(Location,Microsoft.OData.SampleService.Models.TripPin.AirportLocation)/City/Name eq 'Beijing' should be the same as cast(Location,Microsoft.OData.SampleService.Models.TripPin.AirportLocation)/City/Name eq 'Beijing'
Screenshots
Getting the below after fixing the issue #1744 to SingleResourceCastNode in case of unquoted type parameter:
Additional context
Add a condition to try cast QueryNode to SingleResourceCastNode or ConstantNode
publicvirtual Expression BindSingleResourceCastFunctionCall(SingleResourceFunctionCallNodenode,QueryBinderContextcontext){
...
string targetEdmTypeName =null;QueryNodequeryNode= node.Parameters.Last();if(queryNode is SingleResourceCastNode singleResourceCastNode){targetEdmTypeName= singleResourceCastNode.TypeReference.FullName();}elseif(queryNode is ConstantNode constantNode){targetEdmTypeName= constantNode.Value asstring;}IEdmTypetargetEdmType= model.FindType(targetEdmTypeName);
...}
The text was updated successfully, but these errors were encountered:
Assemblies affected
ASP.NET Core OData 7.x +
Describe the bug
The
BindSingleResourceCastFunctionCall()
method links a "SingleResourceFunctionCallNode" to produce a LINQ "Expression" that signifies the meaning of the "SingleResourceFunctionCallNode".This method takes two arguments:
SingleResourceFunctionCallNode
andQueryBinderContext
.SingleResourceFunctionCallNode
has aParameters
property, which is a list of QueryNodes.The last QueryNode in this
SingleResourceFunctionCallNode.Parameters
parameter could be either of typeConstantNode
orSingleResourceCastNode
.For instance:
SingleResourceFunctionCallNode.Parameters
is of typeSingleResourceCastNode
. This occurs becauseNS.WorkAddress
is bound as a DottedIdentifier and thus transformed into a SingleResourceCastNode.SingleResourceFunctionCallNode.Parameters
is of typeConstantNode
, as'NS.WorkAddress'
is bound as a Literal and consequently converted to ConstantNode.SingleResourceCastNode
.ConstantNode
.etc.
Currently, the implementation only allows for casting to
ConstantNode
: Microsoft.AspNetCore.OData/Query/Expressions/QueryBinder.cs#L620We should be able to cast the parameter as either
SingleResourceCastNode
orConstantNode
in order to enable the solution for this other issue OData/odata.net#1744Reproduce steps
This issue was identified while fixing another issue OData/odata.net#1744
cast
with unquoted type parameter throw an error:/Airports?$filter=cast(Location,Microsoft.OData.SampleService.Models.TripPin.AirportLocation)/City/Name eq 'Beijing'
cast
with quoted type parameter works just fine:/Airports?$filter=cast(Location,Microsoft.OData.SampleService.Models.TripPin.AirportLocation)/City/Name eq 'Beijing'
The above issue is describe here
EDM (CSDL) Model
https://services.odata.org/V4/(S(4dwtx43m0k0tpfool4gce2di))/TripPinServiceRW/$metadata
Expected behavior
cast
with quoted and unquoted type param should return the same data. For examplecast(Location,Microsoft.OData.SampleService.Models.TripPin.AirportLocation)/City/Name eq 'Beijing'
should be the same ascast(Location,Microsoft.OData.SampleService.Models.TripPin.AirportLocation)/City/Name eq 'Beijing'
Screenshots
Getting the below after fixing the issue #1744 to
SingleResourceCastNode
in case ofunquoted
type parameter:Additional context
Add a condition to try cast QueryNode to
SingleResourceCastNode
orConstantNode
The text was updated successfully, but these errors were encountered: