{"record":{"id":"b2784bdb2c87e9e5","repo":"dotnet/efcore","slug":"the-linq-expression-expression-could-not-be-tr-b2784b","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/RelationalQueryableMethodTranslatingExpressionVisitor.cs","lineNumber":140,"sourceCode":"                    {\n                        string call;\n                        var methodInfo = function.DbFunctions.Last().MethodInfo;\n                        if (methodInfo != null)\n                        {\n                            var methodCall = Expression.Call(\n                                // Declaring types would be derived db context.\n                                Expression.Default(methodInfo.DeclaringType!),\n                                methodInfo,\n                                tableValuedFunctionQueryRootExpression.Arguments);\n\n                            call = methodCall.Print();\n                        }\n                        else\n                        {\n                            call = $\"{function.DbFunctions.Last().Name}()\";\n                        }\n\n                        throw new InvalidOperationException(\n                            TranslationErrorDetails == null\n                                ? CoreStrings.TranslationFailed(call)\n                                : CoreStrings.TranslationFailedWithDetails(call, TranslationErrorDetails));\n                    }\n\n                    arguments.Add(sqlArgument);\n                }\n\n                var entityType = tableValuedFunctionQueryRootExpression.EntityType;\n                var alias = _sqlAliasManager.GenerateTableAlias(function);\n                var translation = new TableValuedFunctionExpression(alias, function, arguments);\n                var queryExpression = CreateSelect(entityType, translation);\n\n                return CreateShapedQueryExpression(entityType, queryExpression);\n            }\n\n            case EntityQueryRootExpression entityQueryRootExpression\n                when entityQueryRootExpression.GetType() == typeof(EntityQueryRootExpression)","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.cs#L122-L158","documentation":"Generic EF Core translation-failure message (no detail list) thrown when a LINQ expression — typically a TVF/db-function argument — could not be translated to SQL and TranslationErrorDetails is null. The user is told to rewrite the query or explicitly switch to client evaluation.","triggerScenarios":"Calling a table-valued function or DB function whose argument (or the function itself) the relational translator cannot render as SQL, with no per-element error details collected. The source region is the TVF-argument translation loop's throw.","commonSituations":"Using an unmapped custom method inside a query, a TVF with an unsupported argument expression, mixing client-side methods into a server-side query, or hitting a provider translation gap.","solutions":["Identify the printed expression in the error and simplify it (remove client-side method calls, computed members).","Insert AsEnumerable()/ToList() before the unsupported operator to force client evaluation of that portion.","Check that the DB function / TVF is registered and its arguments are mapped properties or literals.","If a provider translation is missing, file an issue or upgrade the provider."],"exampleFix":"// before\nvar q = ctx.Customers.FromSqlInterpolated($\"SELECT * FROM dbo.GetCustomers({someExpr()})\");\n// after — evaluate the argument client-side\nvar arg = someExpr();\nvar q = ctx.Customers.FromSqlInterpolated($\"SELECT * FROM dbo.GetCustomers({arg})\");","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { var r = await query.ToListAsync(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"could not be translated\"))\n{\n    logger.LogWarning(\"Translation failed; falling back to client eval: {Msg}\", ex.Message);\n    var r = await query.AsEnumerable().ToListAsync(); // already materialized\n}","preventionTips":["Keep server-side queries to translatable operators only.","Evaluate client-side expressions before the query.","Register TVFs/DB functions and verify their argument shapes."],"tags":["efcore","query-translation","linq","client-evaluation"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}