{"record":{"id":"cec9cdcd8edf60a9","repo":"dotnet/efcore","slug":"the-linq-expression-expression-could-not-be-tr-cec9cd","errorCode":null,"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/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.cs#L122-L158","documentation":"The detailed variant of translation failure: same throw site as 617, but TranslationErrorDetails is non-null so EF Core appends the collected per-sub-expression translation errors. Use the details to pinpoint which sub-expression of the LINQ tree failed.","triggerScenarios":"Same TVF/db-function argument translation failure, but the translator collected sub-expression error details (e.g. 'could not translate MyClientMethod()' or 'Sum over byte not supported').","commonSituations":"Complex queries where multiple parts may fail; provider-specific gaps that surface with explanatory detail.","solutions":["Read the {details} segment to find the specific sub-expression that failed and address it first.","Rewrite or remove the flagged sub-expression; push down only translatable constructs.","Switch the failing portion to client evaluation with AsEnumerable/ToList.","Upgrade the provider if the detail indicates a known translation gap."],"exampleFix":"// before\nvar q = ctx.Orders.Where(o => o.Items.Sum(i => i.Weight * i.Count) > 100);\n// detail: Sum over expression not supported -> precompute\n// after\nvar q = ctx.Orders\n    .AsEnumerable()\n    .Where(o => o.Items.Sum(i => i.Weight * i.Count) > 100);","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { await query.ToListAsync(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"could not be translated\"))\n{\n    // ex.Message includes Additional information: <details> — log it for diagnosis.\n    logger.LogError(ex, \"Translation failed with details\");\n    var fallback = query.AsEnumerable(); // client-side\n}","preventionTips":["Read the {details} segment first; it points at the offending sub-expression.","Push only translatable constructs server-side; client-eval the rest after AsEnumerable.","Add regression tests for previously failing query 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"}