litedb-org / LiteDB

LiteDB - A .NET NoSQL Document Store in a single data file
http://www.litedb.org
MIT License
8.66k stars 1.25k forks source link

Exception when Using ToLowerInvariant() in Query Expression #2467

Closed KrzysztofPajak closed 5 months ago

KrzysztofPajak commented 7 months ago

Version 5.0.19 Exception: Method ToLowerInvariant() in String are not supported when convert to BsonExpression

Describe the bug When using the ToLowerInvariant() method within the query expression, LiteDB throws an exception. This behavior occurs consistently whenever ToLowerInvariant() is utilized in the query expression.

Code to Reproduce Create a query expression using ToLowerInvariant() method. Execute the query with LiteDB. Expected Behavior: The query should execute without throwing any exceptions, even when ToLowerInvariant() method is used.

Code Example: collection.FindOne(x => x.Id == "1".ToLowerInvariant())

Actual Behavior: LiteDB throws an exception when ToLowerInvariant() method is used in the query expression.

StackTrace: at LiteDB.LinqExpressionVisitor.VisitMethodCall(MethodCallExpression node) at LiteDB.LinqExpressionVisitor.VisitAsPredicate(Expression expr, Boolean ensurePredicate) at LiteDB.LinqExpressionVisitor.VisitBinary(BinaryExpression node) at System.Linq.Expressions.ExpressionVisitor.VisitLambda[T](Expression1 node) at LiteDB.LinqExpressionVisitor.VisitLambda[T](Expression1 node) at LiteDB.LinqExpressionVisitor.Resolve(Boolean predicate) at LiteDB.BsonMapper.GetExpression[T,K](Expression1 predicate) at LiteDB.LiteCollection1.FindOne(Expression`1 predicate)

JKamsker commented 5 months ago

This issue has been resolved in the latest version