@@ -80,68 +80,73 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
8080
8181 var innerExpression = root . UnwrapTypeConversion ( out var convertedType ) ;
8282 var structuralTypeReference = UnwrapStructuralTypeReference ( innerExpression ) ;
83- var entityReference = structuralTypeReference as EntityReference ;
84- if ( entityReference is not null )
83+
84+ ITypeBase structuralType ;
85+
86+ switch ( structuralTypeReference )
8587 {
86- var entityType = entityReference . EntityType ;
87- if ( convertedType != null )
88- {
89- entityType = entityType . GetAllBaseTypes ( ) . Concat ( entityType . GetDerivedTypesInclusive ( ) )
90- . FirstOrDefault ( et => et . ClrType == convertedType ) ;
91- if ( entityType == null )
88+ case EntityReference { EntityType : var entityType } entityReference :
89+ if ( convertedType != null )
9290 {
93- return null ;
91+ entityType = entityType . GetAllBaseTypes ( ) . Concat ( entityType . GetDerivedTypesInclusive ( ) )
92+ . FirstOrDefault ( et => et . ClrType == convertedType ) ;
93+ if ( entityType == null )
94+ {
95+ return null ;
96+ }
9497 }
95- }
9698
97- var navigation = memberIdentity . MemberInfo is not null
98- ? entityType . FindNavigation ( memberIdentity . MemberInfo )
99- : memberIdentity . Name is not null
100- ? entityType . FindNavigation ( memberIdentity . Name )
101- : null ;
102- if ( navigation is not null )
103- {
104- return ExpandNavigation ( root , entityReference , navigation , convertedType is not null ) ;
105- }
99+ // Attempt to bind navigations; these are only relevant to entity types
100+ var navigation = memberIdentity . MemberInfo is not null
101+ ? entityType . FindNavigation ( memberIdentity . MemberInfo )
102+ : memberIdentity . Name is not null
103+ ? entityType . FindNavigation ( memberIdentity . Name )
104+ : null ;
105+ if ( navigation is not null )
106+ {
107+ return ExpandNavigation ( root , entityReference , navigation , convertedType is not null ) ;
108+ }
106109
107- var skipNavigation = memberIdentity . MemberInfo is not null
108- ? entityType . FindSkipNavigation ( memberIdentity . MemberInfo )
109- : memberIdentity . Name is not null
110- ? entityType . FindSkipNavigation ( memberIdentity . Name )
111- : null ;
112- if ( skipNavigation is not null )
113- {
114- return ExpandSkipNavigation ( root , entityReference , skipNavigation , convertedType is not null ) ;
115- }
110+ var skipNavigation = memberIdentity . MemberInfo is not null
111+ ? entityType . FindSkipNavigation ( memberIdentity . MemberInfo )
112+ : memberIdentity . Name is not null
113+ ? entityType . FindSkipNavigation ( memberIdentity . Name )
114+ : null ;
115+ if ( skipNavigation is not null )
116+ {
117+ return ExpandSkipNavigation ( root , entityReference , skipNavigation , convertedType is not null ) ;
118+ }
119+
120+ structuralType = entityType ;
121+ break ;
122+
123+ case ComplexTypeReference { ComplexType : var complexType } :
124+ structuralType = complexType ;
125+ break ;
126+
127+ default :
128+ return null ;
116129 }
117130
118- var structuralType = entityReference is not null
119- ? ( ITypeBase ) entityReference . EntityType
120- : structuralTypeReference is ComplexTypeReference complexTypeReference
121- ? complexTypeReference . ComplexType
131+ // Attempt to bind complex and primitive collection properties; these are common to both entity and complex types
132+ var complexProperty = memberIdentity . MemberInfo != null
133+ ? structuralType . FindComplexProperty ( memberIdentity . MemberInfo )
134+ : memberIdentity . Name is not null
135+ ? structuralType . FindComplexProperty ( memberIdentity . Name )
122136 : null ;
123-
124- if ( structuralType is not null )
137+ if ( complexProperty is not null )
125138 {
126- var complexProperty = memberIdentity . MemberInfo != null
127- ? structuralType . FindComplexProperty ( memberIdentity . MemberInfo )
128- : memberIdentity . Name is not null
129- ? structuralType . FindComplexProperty ( memberIdentity . Name )
130- : null ;
131- if ( complexProperty is not null )
132- {
133- return new ComplexPropertyReference ( root , complexProperty , originalExpression ) ;
134- }
139+ return new ComplexPropertyReference ( root , complexProperty , originalExpression ) ;
140+ }
135141
136- var property = memberIdentity . MemberInfo != null
137- ? structuralType . FindProperty ( memberIdentity . MemberInfo )
138- : memberIdentity . Name is not null
139- ? structuralType . FindProperty ( memberIdentity . Name )
140- : null ;
141- if ( property ? . IsPrimitiveCollection == true )
142- {
143- return new PrimitiveCollectionReference ( root , property ) ;
144- }
142+ var property = memberIdentity . MemberInfo != null
143+ ? structuralType . FindProperty ( memberIdentity . MemberInfo )
144+ : memberIdentity . Name is not null
145+ ? structuralType . FindProperty ( memberIdentity . Name )
146+ : null ;
147+ if ( property ? . IsPrimitiveCollection == true )
148+ {
149+ return new PrimitiveCollectionReference ( root , property ) ;
145150 }
146151
147152 return null ;
0 commit comments