Skip to content

Commit 9554778

Browse files
Merge pull request #541 from mnsrulz/master
allow select without table to support cross apply
2 parents a1f8e3f + 666e112 commit 9554778

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

QueryBuilder.Tests/SelectTests.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,5 +814,24 @@ public void EscapeClauseThrowsForMultipleCharacters()
814814
.HavingContains("Column1", @"TestString\%", false, @"\aa");
815815
});
816816
}
817+
818+
819+
[Fact]
820+
public void BasicSelectRaw_WithNoTable()
821+
{
822+
var q = new Query().SelectRaw("somefunction() as c1");
823+
824+
var c = Compilers.CompileFor(EngineCodes.SqlServer, q);
825+
Assert.Equal("SELECT somefunction() as c1", c.ToString());
826+
}
827+
828+
[Fact]
829+
public void BasicSelect_WithNoTable()
830+
{
831+
var q = new Query().Select("c1");
832+
var c = Compilers.CompileFor(EngineCodes.SqlServer, q);
833+
Assert.Equal("SELECT [c1]", c.ToString());
834+
}
835+
817836
}
818837
}

QueryBuilder/Compilers/Compiler.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -647,14 +647,14 @@ public virtual string CompileTableExpression(SqlResult ctx, AbstractFrom from)
647647

648648
public virtual string CompileFrom(SqlResult ctx)
649649
{
650-
if (!ctx.Query.HasComponent("from", EngineCode))
650+
if (ctx.Query.HasComponent("from", EngineCode))
651651
{
652-
throw new InvalidOperationException("No table is set");
653-
}
652+
var from = ctx.Query.GetOneComponent<AbstractFrom>("from", EngineCode);
654653

655-
var from = ctx.Query.GetOneComponent<AbstractFrom>("from", EngineCode);
654+
return "FROM " + CompileTableExpression(ctx, from);
655+
}
656656

657-
return "FROM " + CompileTableExpression(ctx, from);
657+
return string.Empty;
658658
}
659659

660660
public virtual string CompileJoins(SqlResult ctx)

0 commit comments

Comments
 (0)