@@ -114,6 +114,46 @@ private static string ParseMethodName(InvocationExpressionSyntax node)
114114 return propertyName ;
115115 }
116116
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+ }
117157
118158 private void ParseHasOne ( InvocationExpressionSyntax node )
119159 {
@@ -151,13 +191,17 @@ private void ParseForeignKey(InvocationExpressionSyntax node)
151191 if ( node == null || ParsedEntity == null )
152192 return ;
153193
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 ) ;
155199
156- if ( string . IsNullOrEmpty ( propertyName ) )
200+ if ( propertyNames == null )
157201 return ;
158202
159203 _currentRelationship ??= new ParsedRelationship ( ) ;
160- _currentRelationship . Properties . Add ( propertyName ) ;
204+ _currentRelationship . Properties . AddRange ( propertyNames ) ;
161205 }
162206
163207 private void ParseConstraintName ( InvocationExpressionSyntax node )
0 commit comments