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