{"record":{"id":"d302b7a23ec66bf7","repo":"dotnet/efcore","slug":"the-linq-expression-expression-could-not-be-tr-d302b7","errorCode":null,"errorMessage":"The LINQ expression '{expression}' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'. See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.","messagePattern":"The LINQ expression '(.+?)' could not be translated\\. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'\\. See https://go\\.microsoft\\.com/fwlink/\\?linkid=2101038 for more information\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Relational/Query/Internal/RelationalProjectionBindingExpressionVisitor.cs","lineNumber":131,"sourceCode":"\n            case null:\n                return null;\n\n            case not null when _indexBasedBinding:\n            {\n                switch (expression)\n                {\n                    case ConstantExpression:\n                        return expression;\n\n                    case QueryParameterExpression queryParameterExpression:\n                        return Expression.Call(\n                            GetParameterValueMethodInfo.MakeGenericMethod(queryParameterExpression.Type),\n                            QueryCompilationContext.QueryContextParameter,\n                            Expression.Constant(queryParameterExpression.Name));\n\n                    case ParameterExpression parameterExpression:\n                        throw new InvalidOperationException(CoreStrings.TranslationFailed(parameterExpression.Print()));\n\n                    case ProjectionBindingExpression projectionBindingExpression:\n                        return _selectExpression.GetProjection(projectionBindingExpression) switch\n                        {\n                            StructuralTypeProjectionExpression projection => AddClientProjection(projection, typeof(ValueBuffer)),\n                            SqlExpression mappedSqlExpression => AddClientProjection(mappedSqlExpression, expression.Type.MakeNullable()),\n                            // A single-result subquery (e.g. the group element of GroupBy(k).Select(g => g.First()))\n                            // being composed over: lower it into the current select as a to-one join so the result\n                            // has a bindable shape, instead of failing.\n                            ShapedQueryExpression\n                            {\n                                ResultCardinality: ResultCardinality.Single or ResultCardinality.SingleOrDefault\n                            } singleResultSubquery\n                                => LowerSingleResultSubquery(projectionBindingExpression, singleResultSubquery),\n                            _ => throw new InvalidOperationException(CoreStrings.TranslationFailed(projectionBindingExpression.Print()))\n                        };\n\n                    case MaterializeCollectionNavigationExpression materializeCollectionNavigationExpression:","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Relational/Query/Internal/RelationalProjectionBindingExpressionVisitor.cs#L113-L149","documentation":"Thrown by the relational projection binding visitor when it encounters a ParameterExpression that cannot be translated to SQL while performing index-based projection binding. This means a LINQ projection referenced a parameter (like a closure variable or an unbound parameter expression) that EF Core's query translator could not map to a SQL expression, and it falls through to client evaluation which is disabled by default.","triggerScenarios":"Writing a LINQ Select() projection that references a ParameterExpression directly — typically an untranslatable lambda parameter, an external closure variable used inside a projection in a way the translator can't inline, or a custom expression tree node that reduces to a bare ParameterExpression.","commonSituations":"Using a method call inside Select() that EF cannot translate (e.g., calling a custom method, using ToString with format strings on unsupported providers). Referencing a local variable in a way that creates an unbound parameter. Using complex projections with conditional logic that the translator can't handle. Provider-specific limitation (e.g., SQLite not supporting a SQL Server function).","solutions":["Rewrite the projection to only use translatable operations — move non-translatable logic after AsEnumerable() so it runs client-side.","Split the query: use Select() with only server-side fields, call ToList()/AsEnumerable(), then project further client-side.","If referencing a parameterized value, ensure it's passed as a query parameter (variable in an interpolated lambda) not as an expression parameter.","Check the EF Core docs for supported translations of the specific pattern you're using."],"exampleFix":"// before\nvar result = context.Blogs\n    .Select(b => new { Title = b.Title, Formatted = FormatBlog(b) }) // FormatBlog is untranslatable\n    .ToList();\n\n// after\nvar result = context.Blogs\n    .Select(b => new { b.Title, b.Content })\n    .AsEnumerable()\n    .Select(b => new { b.Title, Formatted = FormatBlog(b) })\n    .ToList();","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try\n{\n    var result = await context.Blogs\n        .Select(b => new { b.Title, Computed = SomeUntranslatableCall(b) })\n        .ToListAsync();\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"could not be translated\"))\n{\n    // Fallback: split into server-side + client-side projection\n    var raw = await context.Blogs.Select(b => new { b.Title, b.Content }).ToListAsync();\n    var result = raw.Select(b => new { b.Title, Computed = SomeUntranslatableCall(b) }).ToList();\n}","preventionTips":["Keep server-side projections simple — only map properties and basic expressions EF can translate.","Move non-translatable logic after AsEnumerable() or ToListAsync().","Review the EF Core supported query patterns documentation for your provider.","Write integration tests for complex queries to catch translation failures early."],"tags":["linq-translation","projection","client-evaluation","parameter-expression"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}