@@ -186,23 +186,37 @@ System.Threading.CancellationToken cancellationToken
186186 return false ;
187187 }
188188
189- // Get the type of the expression before .Select()
190- var typeInfo = semanticModel . GetTypeInfo ( memberAccess . Expression , cancellationToken ) ;
191- var type = typeInfo . Type ;
189+ return IsDbSetExpression ( memberAccess . Expression , semanticModel , cancellationToken ) ;
190+ }
192191
193- if ( type == null )
194- {
195- return false ;
196- }
192+ private static bool IsDbSetExpression (
193+ ExpressionSyntax expression ,
194+ SemanticModel semanticModel ,
195+ System . Threading . CancellationToken cancellationToken
196+ )
197+ {
198+ var current = expression ;
197199
198- // Check if it's DbSet<T>
199- if ( type is INamedTypeSymbol namedType )
200+ while ( true )
200201 {
201- var displayString = namedType . OriginalDefinition . ToDisplayString ( ) ;
202- if ( displayString . StartsWith ( "Microsoft.EntityFrameworkCore.DbSet<" ) )
202+ var typeInfo = semanticModel . GetTypeInfo ( current , cancellationToken ) ;
203+ if ( typeInfo . Type is INamedTypeSymbol namedType )
204+ {
205+ var displayString = namedType . OriginalDefinition . ToDisplayString ( ) ;
206+ if ( displayString . StartsWith ( "Microsoft.EntityFrameworkCore.DbSet<" ) )
207+ {
208+ return true ;
209+ }
210+ }
211+
212+ if ( current is InvocationExpressionSyntax invocation
213+ && invocation . Expression is MemberAccessExpressionSyntax invocationMemberAccess )
203214 {
204- return true ;
215+ current = invocationMemberAccess . Expression ;
216+ continue ;
205217 }
218+
219+ break ;
206220 }
207221
208222 return false ;
0 commit comments