@@ -803,5 +803,40 @@ public void EscapeClauseThrowsForMultipleCharacters()
803803 . HavingContains ( "Column1" , @"TestString\%" , false , @"\aa" ) ;
804804 } ) ;
805805 }
806+
807+
808+ [ Fact ]
809+ public void BasicSelectRaw_WithNoTable ( )
810+ {
811+ var q = new Query ( ) . SelectRaw ( "somefunction() as c1" ) ;
812+
813+ var c = Compilers . CompileFor ( EngineCodes . SqlServer , q ) ;
814+ Assert . Equal ( "SELECT somefunction() as c1" , c . ToString ( ) ) ;
815+ }
816+
817+ [ Fact ]
818+ public void BasicSelect_WithNoTable ( )
819+ {
820+ var q = new Query ( ) . Select ( "c1" ) ;
821+ var c = Compilers . CompileFor ( EngineCodes . SqlServer , q ) ;
822+ Assert . Equal ( "SELECT [c1]" , c . ToString ( ) ) ;
823+ }
824+
825+ [ Fact ]
826+ public void CrossApply_Column_Reusability ( )
827+ {
828+ var q = new Query ( "users" ) . Select ( "name" , "salary" , "taxbracket" , "taxamount" , "grosspay" )
829+ . CrossApply ( new Query ( ) . SelectRaw ( "case when salary < 5000 then 10 when salary < 10000 then 20 else 30 end as taxbracket" ) . As ( "t1" ) , j => j )
830+ . CrossApply ( new Query ( ) . SelectRaw ( "salary * taxbracket as taxamount" ) . As ( "t2" ) , j => j )
831+ . CrossApply ( new Query ( ) . SelectRaw ( "salary - taxamount as grosspay" ) . As ( "t3" ) , j => j ) ;
832+ var c = Compilers . CompileFor ( EngineCodes . SqlServer , q ) ;
833+
834+ Assert . Equal ( string . Join ( "\n " , new [ ] {
835+ "SELECT [name], [salary], [taxbracket], [taxamount], [grosspay] FROM [users] " ,
836+ "CROSS APPLY (SELECT case when salary < 5000 then 10 when salary < 10000 then 20 else 30 end as taxbracket) AS [t1]" ,
837+ "CROSS APPLY (SELECT salary * taxbracket as taxamount) AS [t2]" ,
838+ "CROSS APPLY (SELECT salary - taxamount as grosspay) AS [t3]" ,
839+ } ) , c . ToString ( ) ) ;
840+ }
806841 }
807842}
0 commit comments