{"record":{"id":"53549a778e4b0a40","repo":"litedb-org/LiteDB","slug":"0-53549a","errorCode":"0","errorMessage":"Any/All requires simple parameter on left side. Eg: `x => x.Phones.Select(p => p.Number).Any(n => n > 5)`","messagePattern":"Any/All requires simple parameter on left side\\. Eg: `x => x\\.Phones\\.Select\\(p => p\\.Number\\)\\.Any\\(n => n > 5\\)`","errorType":"exception","errorClass":"LiteException","httpStatus":null,"severity":"error","filePath":"LiteDB/Client/Mapper/Linq/LinqExpressionVisitor.cs","lineNumber":565,"sourceCode":"                else\n                {\n                    _builder.Append(token.Type == TokenType.String ? \"'\" + token.Value + \"'\" : token.Value);\n                }\n            }\n        }\n\n        /// <summary>\n        /// Resolve Enumerable predicate when using Any/All enumerable extensions\n        /// </summary>\n        private void VisitEnumerablePredicate(LambdaExpression lambda)\n        {\n            var expression = lambda.Body;\n\n            // Visit .Any(x => `x == 10`)\n            if (expression is BinaryExpression bin)\n            {\n                // requires only parameter in left side\n                if (bin.Left.NodeType != ExpressionType.Parameter) throw new LiteException(0, \"Any/All requires simple parameter on left side. Eg: `x => x.Phones.Select(p => p.Number).Any(n => n > 5)`\");\n\n                var op = this.GetOperator(bin.NodeType);\n\n                _builder.Append(op);\n\n                this.VisitAsPredicate(bin.Right, false);\n            }\n            // Visit .Any(x => `x.StartsWith(\"John\")`)\n            else if (expression is MethodCallExpression met)\n            {\n                // requires only parameter in left side\n                if (met.Object.NodeType != ExpressionType.Parameter) throw new NotSupportedException(\"Any/All requires simple parameter on left side. Eg: `x.Customers.Select(c => c.Name).Any(n => n.StartsWith('J'))`\");\n\n                // if not found in resolver, try run method\n                if (!TryGetResolver(met.Method.DeclaringType, out var type))\n                {\n                    throw new NotSupportedException($\"Method {met.Method.Name} not available to convert to BsonExpression inside Any/All call.\");\n                }","sourceCodeStart":547,"sourceCodeEnd":583,"githubUrl":"https://github.com/litedb-org/LiteDB/blob/f906a5f850678719e39a39a006cb66dcae563cfa/LiteDB/Client/Mapper/Linq/LinqExpressionVisitor.cs#L547-L583","documentation":"Thrown by VisitEnumerablePredicate when the body of an Any/All lambda is a BinaryExpression whose left operand is not a bare ParameterExpression. LiteDB's Any/All translation requires the comparison to be directly against the lambda parameter (e.g., n => n > 5), not against a member of it (e.g., n => n.Value > 5). The fix is to flatten with Select first.","triggerScenarios":"Writing x.Items.Any(i => i.Price > 100) where the left side i.Price is a member access, not the parameter i itself. The Any/All predicate body is a BinaryExpression and bin.Left.NodeType is not ExpressionType.Parameter.","commonSituations":"Intuitively writing .Any(lambda) on a collection of complex objects and comparing a property inside the lambda, without first selecting the property. Assuming Any/All supports full nested member comparisons like EF Core does.","solutions":["Insert a .Select(p => p.Field) before .Any(n => n > value) so the Any lambda compares the parameter directly.","Restructure the query so the Any/All lambda body is a direct binary comparison against the lambda parameter."],"exampleFix":"// before\ncol.Find(x => x.Items.Any(i => i.Price > 100));\n// throws: Any/All requires simple parameter on left side\n\n// after -- Select the field first\ncol.Find(x => x.Items.Select(i => i.Price).Any(p => p > 100));","handlingStrategy":"validation","validationCode":"// Ensure Any/All lambda bodies are direct comparisons against the parameter\n// Correct: .Select(p => p.Field).Any(n => n > value)\n// Incorrect: .Any(i => i.Field > value)","typeGuard":"// Check that an Any/All lambda body is a direct parameter comparison\nstatic bool IsSimpleAnyAllPredicate<T, K>(Expression<Func<T, K>> expr)\n{\n    if (expr.Body is BinaryExpression bin)\n        return bin.Left.NodeType == ExpressionType.Parameter;\n    return false;\n}","tryCatchPattern":"try\n{\n    var results = col.Find(x => x.Items.Any(i => i.Price > 100));\n}\ncatch (LiteException ex) when (ex.Message.Contains(\"Any/All requires simple parameter on left side\"))\n{\n    results = col.Find(x => x.Items.Select(i => i.Price).Any(p => p > 100));\n}","preventionTips":["Always use .Select(p => p.Field).Any(n => n op value) pattern for Any/All on complex collections.","Keep the Any/All lambda body as a direct binary comparison against the lambda parameter.","Write integration tests for Any/All predicates to catch structural issues early."],"tags":["linq","any-all","enumerable","predicate"],"backgroundTag":null,"analyzedSha":"f906a5f850678719e39a39a006cb66dcae563cfa","analyzedAt":"2026-08-13T21:56:30.148Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}