From 7ce905b6208e48a046ac62989a5bc1495265aefa Mon Sep 17 00:00:00 2001 From: Mark Carrington <31017244+MarkMpn@users.noreply.github.com> Date: Sat, 24 Aug 2024 12:02:19 +0100 Subject: [PATCH] Fixed allowing implicit decimal conversions --- MarkMpn.Sql4Cds.Engine/ExecutionPlan/FoldableJoinNode.cs | 2 +- MarkMpn.Sql4Cds.Engine/ExecutionPlan/SqlTypeConverter.cs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/MarkMpn.Sql4Cds.Engine/ExecutionPlan/FoldableJoinNode.cs b/MarkMpn.Sql4Cds.Engine/ExecutionPlan/FoldableJoinNode.cs index a36a4aa5..1d57ed63 100644 --- a/MarkMpn.Sql4Cds.Engine/ExecutionPlan/FoldableJoinNode.cs +++ b/MarkMpn.Sql4Cds.Engine/ExecutionPlan/FoldableJoinNode.cs @@ -396,7 +396,7 @@ private bool FoldFetchXmlJoin(NodeCompilationContext context, IList le.Items != null) .SelectMany(le => le.Items.OfType()) - .Concat(leftFetch.Entity?.Items.OfType() ?? Enumerable.Empty()) + .Concat(leftFetch.Entity.Items?.OfType() ?? Enumerable.Empty()) .Select(a => a.alias) .Where(alias => alias != null) .Intersect( diff --git a/MarkMpn.Sql4Cds.Engine/ExecutionPlan/SqlTypeConverter.cs b/MarkMpn.Sql4Cds.Engine/ExecutionPlan/SqlTypeConverter.cs index de4a532c..42e9b8fa 100644 --- a/MarkMpn.Sql4Cds.Engine/ExecutionPlan/SqlTypeConverter.cs +++ b/MarkMpn.Sql4Cds.Engine/ExecutionPlan/SqlTypeConverter.cs @@ -382,6 +382,10 @@ public static bool CanChangeTypeImplicit(DataTypeReference from, DataTypeReferen var toType = toSql.SqlDataTypeOption; + // Any numeric type can be implicitly converted to any other. + if (fromType.IsNumeric() && toType.IsNumeric()) + return true; + if (Array.IndexOf(_precendenceOrder, fromType) == -1 || Array.IndexOf(_precendenceOrder, toType) == -1) return false; @@ -390,10 +394,6 @@ public static bool CanChangeTypeImplicit(DataTypeReference from, DataTypeReferen if (fromType.IsStringType() || toType.IsStringType()) return true; - // Any numeric type can be implicitly converted to any other. - if (fromType.IsNumeric() && toType.IsNumeric()) - return true; - // Any numeric type can be implicitly converted to datetime if (fromType.IsNumeric() && (toType == SqlDataTypeOption.DateTime || toType == SqlDataTypeOption.SmallDateTime)) return true;