|
1 | | -// Copyright (C) 2011 Xtensive LLC. |
2 | | -// All rights reserved. |
3 | | -// For conditions of distribution and use, see license. |
| 1 | +// Copyright (C) 2011-2021 Xtensive LLC. |
| 2 | +// This code is distributed under MIT license terms. |
| 3 | +// See the License.txt file in the project root for more information. |
4 | 4 | // Created by: Denis Krjuchkov |
5 | 5 | // Created: 2011.10.07 |
6 | 6 |
|
@@ -46,6 +46,33 @@ public static void BuildFilter(IndexInfo index) |
46 | 46 |
|
47 | 47 | protected override Expression VisitBinary(BinaryExpression b) |
48 | 48 | { |
| 49 | + if (b.Left.StripCasts().Type.StripNullable().IsEnum |
| 50 | + && b.Right.StripCasts().NodeType == ExpressionType.Constant) { |
| 51 | + |
| 52 | + var rawEnum = b.Left.StripCasts(); |
| 53 | + var typeToCast = (rawEnum.Type.IsNullable()) |
| 54 | + ? rawEnum.Type.StripNullable().GetEnumUnderlyingType().ToNullable() |
| 55 | + : rawEnum.Type.GetEnumUnderlyingType(); |
| 56 | + |
| 57 | + return base.VisitBinary(Expression.MakeBinary( |
| 58 | + b.NodeType, |
| 59 | + Expression.Convert(rawEnum, typeToCast), |
| 60 | + Expression.Convert(b.Right, typeToCast))); |
| 61 | + } |
| 62 | + else if (b.Right.StripCasts().Type.StripNullable().IsEnum |
| 63 | + && b.Left.StripCasts().NodeType == ExpressionType.Constant) { |
| 64 | + |
| 65 | + var rawEnum = b.Right.StripCasts(); |
| 66 | + var typeToCast = (rawEnum.Type.IsNullable()) |
| 67 | + ? rawEnum.Type.StripNullable().GetEnumUnderlyingType().ToNullable() |
| 68 | + : rawEnum.Type.GetEnumUnderlyingType(); |
| 69 | + |
| 70 | + return base.VisitBinary(Expression.MakeBinary( |
| 71 | + b.NodeType, |
| 72 | + Expression.Convert(rawEnum, typeToCast), |
| 73 | + Expression.Convert(b.Left, typeToCast))); |
| 74 | + } |
| 75 | + |
49 | 76 | // Detect f!=null and f==null for entity fields |
50 | 77 |
|
51 | 78 | if (!b.NodeType.In(ExpressionType.Equal, ExpressionType.NotEqual)) |
|
0 commit comments