@@ -114,6 +114,46 @@ private static string ParseMethodName(InvocationExpressionSyntax node)
114
114
return propertyName ;
115
115
}
116
116
117
+ private List < string > ParseLambdaExpressionForAnonymousObject ( InvocationExpressionSyntax node )
118
+ {
119
+ if ( node == null )
120
+ return null ;
121
+
122
+ var lambdaExpression = node
123
+ . ArgumentList
124
+ . DescendantNodes ( )
125
+ . OfType < LambdaExpressionSyntax > ( )
126
+ . FirstOrDefault ( ) ;
127
+
128
+ if ( lambdaExpression == null )
129
+ return null ;
130
+
131
+ var anonymousObject = lambdaExpression
132
+ . ChildNodes ( )
133
+ . OfType < AnonymousObjectCreationExpressionSyntax > ( )
134
+ . FirstOrDefault ( ) ;
135
+
136
+ if ( anonymousObject == null )
137
+ return null ;
138
+
139
+ var propertyNames = anonymousObject
140
+ . ChildNodes ( )
141
+ . OfType < AnonymousObjectMemberDeclaratorSyntax > ( )
142
+ . Select ( declarator => declarator
143
+ . ChildNodes ( )
144
+ . OfType < MemberAccessExpressionSyntax > ( )
145
+ . FirstOrDefault ( ) )
146
+ . Where ( memberAccess => memberAccess != null )
147
+ . Select ( memberAccess => memberAccess
148
+ . ChildNodes ( )
149
+ . OfType < IdentifierNameSyntax > ( )
150
+ . Select ( identifier => identifier . Identifier . ValueText )
151
+ . LastOrDefault ( ) )
152
+ . Where ( propertyName => propertyName != null )
153
+ . ToList ( ) ;
154
+
155
+ return propertyNames ;
156
+ }
117
157
118
158
private void ParseHasOne ( InvocationExpressionSyntax node )
119
159
{
@@ -151,13 +191,17 @@ private void ParseForeignKey(InvocationExpressionSyntax node)
151
191
if ( node == null || ParsedEntity == null )
152
192
return ;
153
193
154
- var propertyName = ParseLambaExpression ( node ) ;
194
+ List < string > propertyNames = null ;
195
+ if ( ParseLambaExpression ( node ) is string propertyName && ! string . IsNullOrEmpty ( propertyName ) )
196
+ propertyNames = new List < string > { propertyName } ;
197
+ else
198
+ propertyNames = ParseLambdaExpressionForAnonymousObject ( node ) ;
155
199
156
- if ( string . IsNullOrEmpty ( propertyName ) )
200
+ if ( propertyNames == null )
157
201
return ;
158
202
159
203
_currentRelationship ??= new ParsedRelationship ( ) ;
160
- _currentRelationship . Properties . Add ( propertyName ) ;
204
+ _currentRelationship . Properties . AddRange ( propertyNames ) ;
161
205
}
162
206
163
207
private void ParseConstraintName ( InvocationExpressionSyntax node )
0 commit comments