From 21779c15ced0be027a05475f508ca819b846f578 Mon Sep 17 00:00:00 2001 From: Leonardo Nascimento Date: Wed, 15 Apr 2020 11:40:06 -0300 Subject: [PATCH] Added Linq-to-BsonExpression mapping for non-short-circuit 'AND' and 'OR' --- LiteDB.Tests/Mapper/LinqBsonExpression_Tests.cs | 3 +++ LiteDB/Client/Mapper/Linq/LinqExpressionVisitor.cs | 2 ++ 2 files changed, 5 insertions(+) diff --git a/LiteDB.Tests/Mapper/LinqBsonExpression_Tests.cs b/LiteDB.Tests/Mapper/LinqBsonExpression_Tests.cs index 8e7d8de8c..087025fdb 100644 --- a/LiteDB.Tests/Mapper/LinqBsonExpression_Tests.cs +++ b/LiteDB.Tests/Mapper/LinqBsonExpression_Tests.cs @@ -236,6 +236,9 @@ public void Linq_Predicate() TestPredicate(x => x.Salary != 50, "(Salary != @p0)", 50); TestPredicate(x => x.Salary == x.Id, "(Salary = _id)"); TestPredicate(x => x.Salary > 50 && x.Name == "John", "((Salary > @p0) AND (Name = @p1))", 50, "John"); + TestPredicate(x => x.Salary > 50 & x.Name == "John", "((Salary > @p0) AND (Name = @p1))", 50, "John"); + TestPredicate(x => x.Salary > 50 || x.Name == "John", "((Salary > @p0) OR (Name = @p1))", 50, "John"); + TestPredicate(x => x.Salary > 50 | x.Name == "John", "((Salary > @p0) OR (Name = @p1))", 50, "John"); // unary expressions TestPredicate(x => x.Active, "(Active = true)"); diff --git a/LiteDB/Client/Mapper/Linq/LinqExpressionVisitor.cs b/LiteDB/Client/Mapper/Linq/LinqExpressionVisitor.cs index 71a068370..4f9fa2ff3 100644 --- a/LiteDB/Client/Mapper/Linq/LinqExpressionVisitor.cs +++ b/LiteDB/Client/Mapper/Linq/LinqExpressionVisitor.cs @@ -585,7 +585,9 @@ private string GetOperator(ExpressionType nodeType) case ExpressionType.GreaterThanOrEqual: return " >= "; case ExpressionType.LessThan: return " < "; case ExpressionType.LessThanOrEqual: return " <= "; + case ExpressionType.And: return " AND "; case ExpressionType.AndAlso: return " AND "; + case ExpressionType.Or: return " OR "; case ExpressionType.OrElse: return " OR "; }