Skip to content

Commit f6c59fc

Browse files
iss-581: move exists omit to compiler
1 parent 31ee1e0 commit f6c59fc

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

QueryBuilder/Base.Where.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -539,10 +539,6 @@ public Q WhereExists(Query query)
539539
throw new ArgumentException($"'{nameof(FromClause)}' cannot be empty if used inside a '{nameof(WhereExists)}' condition");
540540
}
541541

542-
// remove unneeded components
543-
query = query.Clone().ClearComponent("select")
544-
.SelectRaw("1");
545-
546542
return AddComponent("where", new ExistsCondition
547543
{
548544
Query = query,

QueryBuilder/Compilers/Compiler.Conditions.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,16 @@ protected virtual string CompileExistsCondition(SqlResult ctx, ExistsCondition i
247247
{
248248
var op = item.IsNot ? "NOT EXISTS" : "EXISTS";
249249

250-
var subCtx = CompileSelectQuery(item.Query);
250+
251+
// remove unneeded components
252+
var query = item.Query.Clone();
253+
254+
if (OmitSelectInsideExists)
255+
{
256+
query.ClearComponent("select").SelectRaw("1");
257+
}
258+
259+
var subCtx = CompileSelectQuery(query);
251260

252261
ctx.Bindings.AddRange(subCtx.Bindings);
253262

0 commit comments

Comments
 (0)