From 53d926876c5b1659311fa0dfa56101ff30016701 Mon Sep 17 00:00:00 2001 From: Samuel Wanjohi Date: Tue, 3 Sep 2024 16:10:29 +0300 Subject: [PATCH] Cast queryNode to SingleResourceCastNode as well --- .../Query/Expressions/QueryBinder.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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;