{"record":{"id":"0643da2a0a115c7d","repo":"litedb-org/LiteDB","slug":"any-all-requires-simple-parameter-on-left-side-eg","errorCode":null,"errorMessage":"Any/All requires simple parameter on left side. Eg: `x.Customers.Select(c => c.Name).Any(n => n.StartsWith('J'))`","messagePattern":"Any/All requires simple parameter on left side\\. Eg: `x\\.Customers\\.Select\\(c => c\\.Name\\)\\.Any\\(n => n\\.StartsWith\\('J'\\)\\)`","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"LiteDB/Client/Mapper/Linq/LinqExpressionVisitor.cs","lineNumber":577,"sourceCode":"            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                }\n\n                // otherwise I have resolver for this method\n                var pattern = type.ResolveMethod(met.Method);\n\n                if (pattern == null || !pattern.StartsWith(\"#\")) throw new NotSupportedException($\"Method {met.Method.Name} not available to convert to BsonExpression inside Any/All call.\");\n\n                // call resolve pattern removing first `#`\n                this.ResolvePattern(pattern.Substring(1), met.Object, met.Arguments);\n            }\n            else\n            {\n                throw new LiteException(0, \"When using Any/All method test do only simple predicate variable. Eg: `x => x.Phones.Select(p => p.Number).Any(n => n > 5)`\");","sourceCodeStart":559,"sourceCodeEnd":595,"githubUrl":"https://github.com/litedb-org/LiteDB/blob/f906a5f850678719e39a39a006cb66dcae563cfa/LiteDB/Client/Mapper/Linq/LinqExpressionVisitor.cs#L559-L595","documentation":"Thrown by VisitEnumerablePredicate when the body of an Any/All lambda is a MethodCallExpression but the method's Object (the instance the method is called on) is not a bare ParameterExpression. For example .Any(n => n.Name.ToUpper()) fails because n.Name is a member access, not the parameter n. The method must be called directly on the lambda parameter.","triggerScenarios":"Writing x.Users.Select(u => u.Name).Any(n => n.ToUpper() == \"JOHN\") where the method is called on something other than the bare parameter. Specifically, met.Object.NodeType is not ExpressionType.Parameter.","commonSituations":"Chaining methods on a member inside an Any/All lambda (e.g., n.Value.ToString()). Forgetting to Select the target field before calling Any/All, so the method call is on a nested member rather than the lambda parameter.","solutions":["Ensure the method inside the Any/All lambda is called directly on the lambda parameter (e.g., .Select(p => p.Name).Any(n => n.StartsWith(\"A\"))).","Flatten the collection with Select to surface the primitive before applying Any/All."],"exampleFix":"// before\ncol.Find(x => x.Users.Any(u => u.Name.ToUpper() == \"JOHN\"));\n\n// after -- Select the field first\ncol.Find(x => x.Users.Select(u => u.Name).Any(n => n.ToUpper() == \"JOHN\"));","handlingStrategy":"validation","validationCode":"// Ensure the method inside Any/All is called directly on the parameter\n// Correct: .Select(p => p.Name).Any(n => n.StartsWith(\"A\"))\n// Incorrect: .Any(u => u.Name.ToUpper().StartsWith(\"A\"))","typeGuard":"// Check that a method inside Any/All is called on the bare parameter\nstatic bool IsAnyAllMethodOnParameter(LambdaExpression lambda)\n{\n    if (lambda.Body is MethodCallExpression mce)\n        return mce.Object?.NodeType == ExpressionType.Parameter;\n    return false;\n}","tryCatchPattern":"try\n{\n    var results = col.Find(x => x.Users.Any(u => u.Name.ToUpper() == \"JOHN\"));\n}\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"Any/All requires simple parameter\"))\n{\n    results = col.Find(x => x.Users.Select(u => u.Name).Any(n => n.ToUpper() == \"JOHN\"));\n}","preventionTips":["Always Select the target field before calling Any/All.","Ensure the method inside Any/All is invoked directly on the lambda parameter.","Keep Any/All predicates simple: one method call on the parameter."],"tags":["linq","any-all","enumerable","method-call"],"backgroundTag":null,"analyzedSha":"f906a5f850678719e39a39a006cb66dcae563cfa","analyzedAt":"2026-08-13T21:56:30.148Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}