Skip to content

Commit 2f99b87

Browse files
committed
Inline ProcessComponentType
1 parent ccf55b4 commit 2f99b87

File tree

1 file changed

+26
-30
lines changed

1 file changed

+26
-30
lines changed

src/NHibernate/Util/ExpressionsHelper.cs

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,13 @@ private static bool TraverseMembers(
197197
IAbstractComponentType currentComponentType = null;
198198
while (memberPaths.Count > 0 && currentType != null)
199199
{
200+
memberPath = member.Path;
200201
var convertType = member.ConvertType;
202+
member = memberPaths.Pop();
201203

202204
switch (currentType)
203205
{
204206
case IAssociationType associationType:
205-
member = memberPaths.Pop();
206207
ProcessAssociationType(
207208
associationType,
208209
sessionFactory,
@@ -213,24 +214,31 @@ private static bool TraverseMembers(
213214
out currentComponentType);
214215
break;
215216
case IAbstractComponentType componentType:
216-
// Concatenate the component property path in order to be able to use EntityMetamodel.GetPropertyType to retrieve the type.
217-
// As GetPropertyType supports only components, do not concatenate when dealing with collection composite elements or elements.
218-
if (!currentType.IsAnyType)
217+
currentComponentType = componentType;
218+
if (currentEntityPersister == null)
219219
{
220-
var nextMember = memberPaths.Pop();
221-
member = currentEntityPersister == null // Collection with composite element or element
222-
? nextMember
223-
: new MemberMetadata($"{member.Path}.{nextMember.Path}", nextMember.ConvertType, nextMember.HasIndexer);
220+
// When persister is not available (q.OneToManyCompositeElement[0].Prop), try to get the type from the component
221+
currentType = TryGetComponentPropertyType(componentType, member.Path);
224222
}
225223
else
226224
{
227-
member = memberPaths.Pop();
225+
if (!currentType.IsAnyType)
226+
{
227+
// Concatenate the component property path in order to be able to use EntityMetamodel.GetPropertyType to retrieve the type.
228+
// As GetPropertyType supports only components, do not concatenate when dealing with collection composite elements or elements.
229+
// q.Component.Prop
230+
member = new MemberMetadata(
231+
$"{memberPath}.{member.Path}",
232+
member.ConvertType,
233+
member.HasIndexer);
234+
}
235+
236+
// q.Component.Prop
237+
currentType = currentEntityPersister.EntityMetamodel.GetPropertyType(member.Path);
228238
}
229-
currentComponentType = componentType;
230-
ProcessComponentType(componentType, currentEntityPersister, member, out currentType);
239+
231240
break;
232241
default:
233-
member = memberPaths.Pop();
234242
// q.Prop.NotMappedProp
235243
currentType = null;
236244
currentEntityPersister = null;
@@ -257,24 +265,12 @@ private static bool TraverseMembers(
257265
return false;
258266
}
259267

260-
private static void ProcessComponentType(
261-
IAbstractComponentType componentType,
262-
IEntityPersister persister,
263-
MemberMetadata member,
264-
out IType memberType)
268+
private static IType TryGetComponentPropertyType(IAbstractComponentType componentType, string memberPath)
265269
{
266-
// When persister is not available (q.OneToManyCompositeElement[0].Prop), try to get the type from the component
267-
if (persister == null)
268-
{
269-
var index = Array.IndexOf(componentType.PropertyNames, member.Path);
270-
memberType = index < 0
271-
? null // q.OneToManyCompositeElement[0].NotMappedProp
272-
: componentType.Subtypes[index]; // q.OneToManyCompositeElement[0].Prop
273-
return;
274-
}
275-
276-
// q.Component.Prop
277-
memberType = persister.EntityMetamodel.GetPropertyType(member.Path);
270+
var index = Array.IndexOf(componentType.PropertyNames, memberPath);
271+
return index < 0
272+
? null // q.OneToManyCompositeElement[0].NotMappedProp
273+
: componentType.Subtypes[index]; // q.OneToManyCompositeElement[0].Prop
278274
}
279275

280276
private static void ProcessAssociationType(
@@ -299,7 +295,7 @@ private static void ProcessAssociationType(
299295
{
300296
case IAbstractComponentType componentType: // q.OneToManyCompositeElement[0].Member
301297
memberComponent = componentType;
302-
ProcessComponentType(componentType, null, member, out memberType);
298+
memberType = TryGetComponentPropertyType(componentType, member.Path);
303299
return;
304300
default: // q.OneToManyElement[0].Member
305301
memberType = null;

0 commit comments

Comments
 (0)