{"record":{"id":"a209dc52e6c17f2a","repo":"dotnet/efcore","slug":"lambda-with-modifiers-not-supported-lambda-modif","errorCode":null,"errorMessage":"Lambda with modifiers not supported: {lambda.Modifiers}","messagePattern":"Lambda with modifiers not supported: (.+?)","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Design/Query/Internal/CSharpToLinqTranslator.cs","lineNumber":1037,"sourceCode":"    /// <summary>\n    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to\n    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in\n    ///     any release. You should only use it directly in your code with extreme caution and knowing that\n    ///     doing so can result in application failures when updating to a new Entity Framework Core release.\n    /// </summary>\n    public override Expression DefaultVisit(SyntaxNode node)\n        => throw new NotSupportedException($\"Unsupported syntax node of type '{node.GetType()}': {node}\");\n\n    private Expression VisitLambdaExpression(AnonymousFunctionExpressionSyntax lambda, Type? expectedType = null)\n    {\n        if (lambda.ExpressionBody is null)\n        {\n            throw new NotSupportedException(\"Lambda with null expression body\");\n        }\n\n        if (lambda.Modifiers.Any())\n        {\n            throw new NotSupportedException(\"Lambda with modifiers not supported: \" + lambda.Modifiers);\n        }\n\n        if (!lambda.AsyncKeyword.IsKind(SyntaxKind.None))\n        {\n            throw new NotSupportedException(\"Async lambdas are not supported\");\n        }\n\n        var lambdaParameters = lambda switch\n        {\n            SimpleLambdaExpressionSyntax simpleLambda => SyntaxFactory.SingletonSeparatedList(simpleLambda.Parameter),\n            ParenthesizedLambdaExpressionSyntax parenthesizedLambda => parenthesizedLambda.ParameterList.Parameters,\n\n            _ => throw new UnreachableException()\n        };\n\n        var translatedParameters = new List<ParameterExpression>();\n        foreach (var parameter in lambdaParameters)\n        {","sourceCodeStart":1019,"sourceCodeEnd":1055,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Design/Query/Internal/CSharpToLinqTranslator.cs#L1019-L1055","documentation":"Thrown by VisitLambdaExpression when lambda.Modifiers.Any() is true. The translator rejects any lambda modifier (e.g. the C# 9 'static' modifier on static lambdas) because it only models plain delegates in LINQ expression trees. Part of EF Core's precompiled-query C#-to-LINQ translation.","triggerScenarios":"Translating C# source containing a static lambda (static () => ...) or any other lambda modifier during precompiled query processing.","commonSituations":"Using C# 9+ static anonymous functions/lambdas inside query code that gets precompiled; source generators encountering modern C# lambda modifier syntax.","solutions":["Remove the modifier (e.g. drop 'static') from the lambda.","If the lambda must not capture, move it to a static helper method and reference that method directly."],"exampleFix":"// before\n.Select(static x => x.Id)\n// after\n.Select(x => x.Id)","handlingStrategy":"validation","validationCode":"foreach (var lambda in root.DescendantNodes().OfType<AnonymousFunctionExpressionSyntax>())\n{\n    if (lambda.Modifiers.Any())\n        throw new InvalidOperationException(\n            $\"Lambda with modifiers ({string.Join(\", \", lambda.Modifiers)}) at {lambda.GetLocation()} is not supported.\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Avoid static lambdas and other modifiers in query code that will be precompiled.","Document the subset of C# lambda syntax supported by precompiled queries for your team."],"tags":["efcore","lambda","expression-trees","csharp","translator"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}