Skip to content

Commit 94f19c3

Browse files
Fixes explicit bool.
1 parent 3216f17 commit 94f19c3

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/CouchDB.Driver/ExpressionVisitors/WhereExpressionVisitor.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ protected override Expression VisitMethodCall(MethodCallExpression m)
2020
return base.VisitMethodCall(m);
2121
}
2222

23+
protected override Expression VisitBinary(BinaryExpression expression)
24+
{
25+
if (expression.Right is ConstantExpression c && c.Type == typeof(bool) &&
26+
(expression.NodeType == ExpressionType.Equal || expression.NodeType == ExpressionType.NotEqual))
27+
{
28+
return expression;
29+
}
30+
return base.VisitBinary(expression);
31+
}
32+
2333
protected override Expression VisitMember(MemberExpression expression)
2434
{
2535
if (IsWhereBooleanExpression(expression))

tests/CouchDB.Driver.UnitTests/Find/Find_Selector.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,5 +98,17 @@ public void Variable_Bool_ExplicitFalse()
9898
var json = rebels.Where(r => r.IsJedi == false).OrderBy(r => r.IsJedi).ToString();
9999
Assert.Equal(@"{""selector"":{""isJedi"":false},""sort"":[""isJedi""]}", json);
100100
}
101+
[Fact]
102+
public void Variable_Bool_ExplicitNotTrue()
103+
{
104+
var json = rebels.Where(r => r.IsJedi != true).OrderBy(r => r.IsJedi).ToString();
105+
Assert.Equal(@"{""selector"":{""isJedi"":{""$ne"":true}},""sort"":[""isJedi""]}", json);
106+
}
107+
[Fact]
108+
public void Variable_Bool_ExplicitNotFalse()
109+
{
110+
var json = rebels.Where(r => r.IsJedi != false).OrderBy(r => r.IsJedi).ToString();
111+
Assert.Equal(@"{""selector"":{""isJedi"":{""$ne"":false}},""sort"":[""isJedi""]}", json);
112+
}
101113
}
102114
}

0 commit comments

Comments
 (0)