@@ -116,6 +116,46 @@ private string ParseLambaExpression(InvocationExpressionSyntax node)
116116 return propertyName ;
117117 }
118118
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+ }
119159
120160 private void ParseHasOne ( InvocationExpressionSyntax node )
121161 {
@@ -153,13 +193,17 @@ private void ParseForeignKey(InvocationExpressionSyntax node)
153193 if ( node == null || ParsedEntity == null )
154194 return ;
155195
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 ) ;
157201
158- if ( string . IsNullOrEmpty ( propertyName ) )
202+ if ( propertyNames == null )
159203 return ;
160204
161205 _currentRelationship ??= new ParsedRelationship ( ) ;
162- _currentRelationship . Properties . Add ( propertyName ) ;
206+ _currentRelationship . Properties . AddRange ( propertyNames ) ;
163207 }
164208
165209 private void ParseConstraintName ( InvocationExpressionSyntax node )
0 commit comments