|
4 | 4 |
|
5 | 5 | namespace CouchDB.Driver.CompositeExpressionsEvaluator
|
6 | 6 | {
|
7 |
| - internal class BoolMemberToConstantEvaluator : ExpressionVisitor |
| 7 | + internal class BoolMemberToConstantEvaluator : ExpressionVisitor |
8 | 8 | {
|
9 |
| - private bool _visitingWhereMethod; |
| 9 | + private bool _isVisitingWhereMethodOrChild; |
10 | 10 |
|
11 | 11 | protected override Expression VisitMethodCall(MethodCallExpression m)
|
12 | 12 | {
|
13 |
| - _visitingWhereMethod = m.Method.Name == nameof(Queryable.Where) && m.Method.DeclaringType == typeof(Queryable); |
14 |
| - if (_visitingWhereMethod) |
| 13 | + bool isRootWhereMethod = !_isVisitingWhereMethodOrChild && m.Method.Name == nameof(Queryable.Where) && m.Method.DeclaringType == typeof(Queryable); |
| 14 | + if (isRootWhereMethod) |
15 | 15 | {
|
16 |
| - Expression result = base.VisitMethodCall(m); |
17 |
| - _visitingWhereMethod = false; |
18 |
| - return result; |
| 16 | + _isVisitingWhereMethodOrChild = true; |
19 | 17 | }
|
20 |
| - return base.VisitMethodCall(m); |
| 18 | + |
| 19 | + Expression result = base.VisitMethodCall(m); |
| 20 | + |
| 21 | + if (isRootWhereMethod) |
| 22 | + { |
| 23 | + _isVisitingWhereMethodOrChild = false; |
| 24 | + } |
| 25 | + |
| 26 | + return result; |
21 | 27 | }
|
22 | 28 |
|
23 | 29 | protected override Expression VisitBinary(BinaryExpression expression)
|
24 | 30 | {
|
25 |
| - if (_visitingWhereMethod && expression.Right is ConstantExpression c && c.Type == typeof(bool) && |
| 31 | + if (_isVisitingWhereMethodOrChild && expression.Right is ConstantExpression c && c.Type == typeof(bool) && |
26 | 32 | (expression.NodeType == ExpressionType.Equal || expression.NodeType == ExpressionType.NotEqual))
|
27 | 33 | {
|
28 | 34 | return expression;
|
@@ -50,8 +56,8 @@ protected override Expression VisitUnary(UnaryExpression expression)
|
50 | 56 |
|
51 | 57 | private bool IsWhereBooleanExpression(MemberExpression expression)
|
52 | 58 | {
|
53 |
| - return _visitingWhereMethod && |
54 |
| - expression.Member is PropertyInfo info && |
| 59 | + return _isVisitingWhereMethodOrChild && |
| 60 | + expression.Member is PropertyInfo info && |
55 | 61 | info.PropertyType == typeof(bool);
|
56 | 62 | }
|
57 | 63 | }
|
|
0 commit comments