Skip to content

Commit

Permalink
Fix Linq expression parsing with ensurePredicate
Browse files Browse the repository at this point in the history
  • Loading branch information
lbnascimento committed Apr 17, 2020
1 parent 21779c1 commit 20f4627
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 4 additions & 4 deletions LiteDB.Tests/Mapper/LinqBsonExpression_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,9 @@ public void Linq_Predicate()

// unary expressions
TestPredicate<User>(x => x.Active, "(Active = true)");
TestPredicate<User>(x => x.Active && x.Active, "((Active = true) AND (Active = true))");
TestPredicate<User>(x => x.Active && x.Active && x.Active, "((($.Active=true) AND ($.Active=true)) AND ($.Active=true))");
TestPredicate<User>(x => x.Active && !x.Active, "((Active = true) AND (Active = false))");
TestPredicate<User>(x => x.Active && x.Active, "(((Active) = true) AND ((Active) = true))");
TestPredicate<User>(x => x.Active && x.Active && x.Active, "(((($.Active)=true) AND (($.Active)=true)) AND (($.Active)=true))");
TestPredicate<User>(x => x.Active && !x.Active, "(((Active) = true) AND (Active = false))");
TestPredicate<User>(x => !x.Active, "(Active = false)");
TestPredicate<User>(x => !x.Active == true, "((Active = false) = @p0)", true);
TestPredicate<User>(x => !(x.Salary == 50), "((Salary = @p0)) = false", 50);
Expand Down Expand Up @@ -278,7 +278,7 @@ public void Linq_Nullables()
TestPredicate<User>(x => x.Latitude > 0, "(Latitude > @p0)", 0);

TestPredicate<User>(x => x.Latitude != null && x.Latitude > 0, "((Latitude != @p0) AND (Latitude > @p1))", BsonValue.Null, 0);
TestPredicate<User>(x => x.Latitude.HasValue && x.Latitude > 0, "(((IS_NULL(Latitude) = false) = true) AND (Latitude > @p0))", 0);
TestPredicate<User>(x => x.Latitude.HasValue && x.Latitude > 0, "((((IS_NULL(Latitude) = false)) = true) AND (Latitude > @p0))", 0);
}

[Fact]
Expand Down
2 changes: 2 additions & 0 deletions LiteDB/Client/Mapper/Linq/LinqExpressionVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -663,8 +663,10 @@ private void VisitAsPredicate(Expression expr, bool ensurePredicate)

if (ensurePredicate)
{
_builder.Append("(");
_builder.Append("(");
base.Visit(expr);
_builder.Append(")");
_builder.Append(" = true)");
}
else
Expand Down

0 comments on commit 20f4627

Please sign in to comment.