From a5f0f0a97a4476ab14067bbd5b52f68481697f6d Mon Sep 17 00:00:00 2001 From: Mark Carrington <31017244+MarkMpn@users.noreply.github.com> Date: Wed, 27 Mar 2024 08:27:58 +0000 Subject: [PATCH] Fixed filtering on virtual attributes where there are multiple virtual attributes for the same underlying lookup Fixes #443 --- MarkMpn.Sql4Cds.Engine/ExecutionPlan/BaseDataNode.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/MarkMpn.Sql4Cds.Engine/ExecutionPlan/BaseDataNode.cs b/MarkMpn.Sql4Cds.Engine/ExecutionPlan/BaseDataNode.cs index 0da6194a..e86b91d3 100644 --- a/MarkMpn.Sql4Cds.Engine/ExecutionPlan/BaseDataNode.cs +++ b/MarkMpn.Sql4Cds.Engine/ExecutionPlan/BaseDataNode.cs @@ -1081,9 +1081,14 @@ private bool TranslateFetchXMLCriteriaWithVirtualAttributes(NodeCompilationConte // it's not always the same under the hood. if (attributeSuffix == "name") { + // Should normally only be one string virtual attribute related to the lookup attribute and one yomi one. Sometimes + // the yomi version is not flagged as such, and some special cases have additional ones as well + // https://github.com/MarkMpn/Sql4Cds/issues/443 attribute = meta.Attributes .OfType() - .SingleOrDefault(a => a.AttributeOf == attrName && a.AttributeType == AttributeTypeCode.String && a.YomiOf == null); + .Where(a => a.AttributeOf == attrName && a.AttributeType == AttributeTypeCode.String && a.YomiOf == null) + .OrderBy(a => a.LogicalName == attrName + "name" ? 0 : 1) + .FirstOrDefault(); } else {