{"record":{"id":"60d05fc940026574","repo":"dotnet/efcore","slug":"translationfailedwithdetails","errorCode":"TranslationFailedWithDetails","errorMessage":"The LINQ expression '{expression}' could not be translated. Additional information: {details} 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\\. Additional information: (.+?) 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/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.cs#L122-L158","documentation":"Same translation-failure path as 656, but when TranslationErrorDetails is non-null (line 141-143), CoreStrings.TranslationFailedWithDetails is thrown instead, appending the accumulated detailed sub-error messages. The details often pinpoint which nested expression first failed to translate, making diagnosis easier than the bare TranslationFailed.","triggerScenarios":"A complex LINQ query where translation fails and the translator collected one or more detailed error strings (e.g. from nested subquery translation, TVF arguments, or group-by element translation). The wrapped details identify the inner untranslatable expressions.","commonSituations":"Deeply nested queries, subqueries inside Select, TVF calls with multiple failing arguments, composite expressions where the first failure triggers detail collection; upgrading EF Core where stricter translation surfaces previously-implicit client evaluation.","solutions":["Read the 'Additional information' details to find the specific inner expression that failed, then target that fragment.","Rewrite the failing fragment to a translatable form (parameters, supported methods, EF.Functions).","Force client evaluation only for the untranslatable sub-expression by splitting the query with AsEnumerable/ToList at the right boundary.","Simplify nested subqueries; materialize intermediate results if needed."],"exampleFix":"// before (nested subquery fails translation; details point to inner method)\nvar q = db.Orders.Select(o => new {\n    o.Id,\n    First = o.Items.OrderBy(i => i.Price).Select(i => Helper.Fmt(i.Sku)).FirstOrDefault()\n});\n\n// after (move untranslatable formatting client-side after projection)\nvar raw = db.Orders.Select(o => new {\n    o.Id,\n    FirstSku = o.Items.OrderBy(i => i.Price).Select(i => i.Sku).FirstOrDefault()\n}).AsEnumerable();\nvar q = raw.Select(o => new { o.Id, First = Helper.Fmt(o.FirstSku) });","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { var r = await query.ToListAsync(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"could not be translated\"))\n{\n    // The 'Additional information' section names the inner failing expression;\n    // target that fragment, rewrite or split with AsEnumerable at the boundary.\n}","preventionTips":["Read the 'Additional information' details to find the first failing inner expression.","Flatten deeply nested subqueries; materialize intermediate results when needed.","Place AsEnumerable/ToList at the exact boundary where client evaluation is acceptable.","Test complex queries in isolation to surface detailed errors early."],"tags":["efcore","query-translation","linq","client-evaluation","diagnostics"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}