From 6e38a8471db9bf2ec4d7869d86eca3080e7fb292 Mon Sep 17 00:00:00 2001 From: Duncan M Date: Mon, 8 Nov 2021 09:06:13 -0700 Subject: [PATCH] Fix TryGetMappedNullability for CompositeCustomType Fixes #2937 --- src/NHibernate.Test/Linq/TryGetMappedTests.cs | 12 ++++++++++++ src/NHibernate/Util/ExpressionsHelper.cs | 6 +++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/NHibernate.Test/Linq/TryGetMappedTests.cs b/src/NHibernate.Test/Linq/TryGetMappedTests.cs index 964072efdc2..44839dccf96 100644 --- a/src/NHibernate.Test/Linq/TryGetMappedTests.cs +++ b/src/NHibernate.Test/Linq/TryGetMappedTests.cs @@ -272,6 +272,18 @@ public void NestedComponentPropertyCastTest() o => o?.Name == "component[OtherProperty1]"); } + [Test] + public void CompositePropertyTest() + { + var query = session.Query().Select(o => o.Multiple.count); + AssertSupported( + query, + typeof(Glarch).FullName, + "Multiple.count", + o => o is Int32Type, + o => o?.Name == typeof(MultiplicityType).FullName); + } + [Test] public void ManyToOneTest() { diff --git a/src/NHibernate/Util/ExpressionsHelper.cs b/src/NHibernate/Util/ExpressionsHelper.cs index 050a4d2ed22..29d9f73d53c 100644 --- a/src/NHibernate/Util/ExpressionsHelper.cs +++ b/src/NHibernate/Util/ExpressionsHelper.cs @@ -158,7 +158,11 @@ internal static bool TryGetMappedNullability( } int index; - if (componentType != null) + if (componentType is CompositeCustomType cct) + { + memberPath = memberPath.Remove(memberPath.LastIndexOf('.')); + } + else if (componentType != null) { index = Array.IndexOf( componentType.PropertyNames,