File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -336,5 +336,15 @@ public void CombineRawWithPlaceholders()
336336 Assert . Equal ( "(SELECT * FROM [Mobiles]) UNION ALL SELECT * FROM [Devices]" , c [ 0 ] ) ;
337337 Assert . Equal ( "(SELECT * FROM `Mobiles`) UNION ALL SELECT * FROM `Devices`" , c [ 1 ] ) ;
338338 }
339+
340+ [ Fact ]
341+ public void NestedEmptyWhere ( )
342+ {
343+ var query = new Query ( "A" ) . Where ( q => new Query ( ) . Where ( q2 => new Query ( ) . Where ( q3 => new Query ( ) ) ) ) ;
344+
345+ var c = Compile ( query ) ;
346+
347+ Assert . Equal ( "SELECT * FROM [A]" , c [ 0 ] ) ;
348+ }
339349 }
340350}
Original file line number Diff line number Diff line change @@ -115,6 +115,11 @@ protected virtual string CompileNestedCondition<Q>(NestedCondition<Q> x) where Q
115115 var sql = CompileConditions ( x . Query . GetComponents < AbstractCondition > ( "where" , EngineCode ) ) ;
116116 var op = x . IsNot ? "NOT " : "" ;
117117
118+ if ( string . IsNullOrEmpty ( sql ) )
119+ {
120+ return "" ;
121+ }
122+
118123 return $ "{ op } ({ sql } )";
119124 }
120125
Original file line number Diff line number Diff line change @@ -484,7 +484,12 @@ protected virtual string CompileWheres(Query query)
484484 }
485485
486486 var conditions = query . GetComponents < AbstractCondition > ( "where" , EngineCode ) ;
487- var sql = CompileConditions ( conditions ) ;
487+ var sql = CompileConditions ( conditions ) . Trim ( ) ;
488+
489+ if ( string . IsNullOrEmpty ( sql ) )
490+ {
491+ return null ;
492+ }
488493
489494 return $ "WHERE { sql } ";
490495 }
You can’t perform that action at this time.
0 commit comments