- 修复 子查询 WhereIf 可能失败的 bug;

This commit is contained in:
2881099 2022-01-04 16:45:17 +08:00
parent 864eca6d72
commit 43e7bdce9c
2 changed files with 33 additions and 14 deletions

View File

@ -689,6 +689,18 @@ namespace FreeSql.Tests.Sqlite
.Any() .Any()
).Any() ).Any()
).ToList(); ).ToList();
sql2222 = select.Where(a =>
select.Where(b => b.Id == a.Id &&
select
.Where(c => c.Id == b.Id)
.Where(d => d.Id == a.Id)
.Where(e => e.Id == b.Id)
.WhereIf(!sql2222.Any(), e => e.Id > 0)
.WhereIf(sql2222.Any(), e => e.Id >= 0)
.Any()
).Any()
).ToList();
} }
[Fact] [Fact]
public void GroupBy() public void GroupBy()

View File

@ -1066,7 +1066,9 @@ namespace FreeSql.Internal
else else
{ {
var argExp = (arg3Exp as UnaryExpression)?.Operand; var argExp = (arg3Exp as UnaryExpression)?.Operand;
if (argExp != null && argExp.NodeType == ExpressionType.Lambda) if (argExp != null)
{
if (argExp.NodeType == ExpressionType.Lambda)
{ {
if (fsqltable1SetAlias == false) if (fsqltable1SetAlias == false)
{ {
@ -1086,6 +1088,11 @@ namespace FreeSql.Internal
} }
} }
} }
else
{
argExp = null;
}
}
args[a] = argExp ?? Expression.Lambda(arg3Exp).Compile().DynamicInvoke(); args[a] = argExp ?? Expression.Lambda(arg3Exp).Compile().DynamicInvoke();
//if (args[a] == null) ExpressionLambdaToSql(call3Exp.Arguments[a], fsqltables, null, null, SelectTableInfoType.From, true); //if (args[a] == null) ExpressionLambdaToSql(call3Exp.Arguments[a], fsqltables, null, null, SelectTableInfoType.From, true);
} }