- 修复 IIF 三元表达式树解析 bool HasValue 问题;

This commit is contained in:
2881099 2022-06-13 19:00:09 +08:00
parent d55ddf4cf8
commit 4549bf446c
2 changed files with 4 additions and 1 deletions

View File

@ -39,6 +39,9 @@ namespace FreeSql.Tests.SqlServerExpression
[Fact] [Fact]
public void Boolean() public void Boolean()
{ {
var s1 = select.Where(a => a.testFieldBoolNullable.HasValue).ToList();
var s2 = select.GroupBy(a => new { IsCheck = a.testFieldBoolNullable.HasValue ? true : false }).ToList(g => g.Key);
var t1 = select.Where(a => a.testFieldBool == true).ToList(); var t1 = select.Where(a => a.testFieldBool == true).ToList();
var t2 = select.Where(a => a.testFieldBool != true).ToList(); var t2 = select.Where(a => a.testFieldBool != true).ToList();
var t3 = select.Where(a => a.testFieldBool == false).ToList(); var t3 = select.Where(a => a.testFieldBool == false).ToList();

View File

@ -691,7 +691,7 @@ namespace FreeSql.Internal
} }
} }
} }
if (leftExp.Type.NullableTypeOrThis() == typeof(bool) && (leftExp.NodeType != ExpressionType.MemberAccess && rightExp.NodeType != ExpressionType.MemberAccess)) if (leftExp.Type.NullableTypeOrThis() == typeof(bool) && (left.EndsWith(" IS NOT NULL") || left.EndsWith(" IS NULL") || leftExp.NodeType != ExpressionType.MemberAccess && rightExp.NodeType != ExpressionType.MemberAccess))
{ {
var leftExpCall = leftExp as MethodCallExpression; var leftExpCall = leftExp as MethodCallExpression;
if (leftExpCall == null || !(leftExpCall.Method.DeclaringType == typeof(SqlExt) && leftExpCall.Method.Name == nameof(SqlExt.IsNull))) if (leftExpCall == null || !(leftExpCall.Method.DeclaringType == typeof(SqlExt) && leftExpCall.Method.Name == nameof(SqlExt.IsNull)))