{"record":{"id":"04f4abbe7e08008f","repo":"dotnet/efcore","slug":"the-linq-expression-expression-could-not-be-tr-04f4ab","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.InMemory/Query/Internal/InMemoryExpressionTranslatingExpressionVisitor.cs","lineNumber":518,"sourceCode":"        };\n\n    /// <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    protected override Expression VisitInvocation(InvocationExpression invocationExpression)\n        => QueryCompilationContext.NotTranslatedExpression;\n\n    /// <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    protected override Expression VisitLambda<T>(Expression<T> lambdaExpression)\n        => throw new InvalidOperationException(CoreStrings.TranslationFailed(lambdaExpression.Print()));\n\n    /// <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    protected override Expression VisitListInit(ListInitExpression listInitExpression)\n        => QueryCompilationContext.NotTranslatedExpression;\n\n    /// <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    protected override Expression VisitMember(MemberExpression memberExpression)\n    {","sourceCodeStart":500,"sourceCodeEnd":536,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.InMemory/Query/Internal/InMemoryExpressionTranslatingExpressionVisitor.cs#L500-L536","documentation":"Thrown by the InMemory query translator when it encounters a LambdaExpression it cannot fold into a translatable expression tree. The InMemory provider only supports a subset of LINQ translation; bare lambdas that are not part of a recognized method (e.g. standalone Func passed to a custom method) hit VisitLambda and the provider surfaces CoreStrings.TranslationFailed with the offending expression.","triggerScenarios":"A LINQ query over an InMemory DbSet whose tree contains a LambdaExpression node the translator does not handle (e.g. invoking a local lambda via a non-translatable method, or composing on an IQueryable after client-side transforms).","commonSituations":"Calling a helper method that takes an Expression<Func<T,bool>> the InMemory translator does not recognize. Mixing in-memory and relational LINQ idioms. Using methods with no InMemory translator (certain string, math, or custom extension methods).","solutions":["Rewrite the query to use only InMemory-translatable operators (Where/Select/OrderBy/GroupBy/Join and primitive comparisons).","Force client evaluation deliberately by inserting .AsEnumerable() before the unsupported operator.","Replace custom extension methods with their primitive equivalents (e.g. compare fields directly instead of through a wrapper).","Move the lambda logic out of the queryable pipeline into a post-projection Select on already-materialized data."],"exampleFix":"// before\ndb.Users.Where(u => MyLocalLambda(u))\n// after\ndb.Users.Where(u => u.Active && u.Age > 18)\n// or force client eval\ndb.Users.AsEnumerable().Where(u => MyLocalLambda(u))","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { return db.Users.Where(predicate).ToList(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"could not be translated\"))\n{\n    return db.Users.AsEnumerable().Where(predicate.Compile()).ToList();\n}","preventionTips":["Use only InMemory-translatable LINQ operators on the server side.","Insert AsEnumerable() before client-side lambdas deliberately.","Avoid passing lambdas to custom extension methods inside queryables."],"tags":["in-memory","query","translation","linq"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}