diff --git a/src/Microsoft.AspNetCore.OData/Query/Expressions/QueryBinder.cs b/src/Microsoft.AspNetCore.OData/Query/Expressions/QueryBinder.cs index 48674407c..9995ac405 100644 --- a/src/Microsoft.AspNetCore.OData/Query/Expressions/QueryBinder.cs +++ b/src/Microsoft.AspNetCore.OData/Query/Expressions/QueryBinder.cs @@ -642,7 +642,17 @@ public virtual Expression BindSingleResourceCastFunctionCall(SingleResourceFunct IEdmModel model = context.Model; - string targetEdmTypeName = (string)((ConstantNode)node.Parameters.Last()).Value; + string targetEdmTypeName = null; + QueryNode queryNode = node.Parameters.Last(); + if (queryNode is ConstantNode constantNode) + { + targetEdmTypeName = constantNode.Value as string; + } + else if (queryNode is SingleResourceCastNode singleResourceCastNode) + { + targetEdmTypeName = singleResourceCastNode.TypeReference.FullName(); + } + IEdmType targetEdmType = model.FindType(targetEdmTypeName); Type targetClrType = null;