@@ -278,6 +278,8 @@ internal string[] ExpressionSelectColumns_MemberAccess_New_NewArrayInit(List<Sel
278278 } ;
279279 internal string ExpressionWhereLambdaNoneForeignObject ( List < SelectTableInfo > _tables , TableInfo table , List < SelectColumnInfo > _selectColumnMap , Expression exp , Func < Expression [ ] , string > getSelectGroupingMapString ) {
280280 var sql = ExpressionLambdaToSql ( exp , new ExpTSC { _tables = _tables , _selectColumnMap = _selectColumnMap , getSelectGroupingMapString = getSelectGroupingMapString , tbtype = SelectTableInfoType . From , isQuoteName = true , isDisableDiyParse = false , style = ExpressionStyle . Where , currentTable = table } ) ;
281+ if ( exp . NodeType == ExpressionType . MemberAccess && exp . Type == typeof ( bool ) )
282+ return $ "{ sql } = { formatSql ( true , null ) } ";
281283 switch ( sql ) {
282284 case "1" :
283285 case "'t'" : return "1=1" ;
@@ -289,6 +291,8 @@ internal string ExpressionWhereLambdaNoneForeignObject(List<SelectTableInfo> _ta
289291
290292 internal string ExpressionWhereLambda ( List < SelectTableInfo > _tables , Expression exp , Func < Expression [ ] , string > getSelectGroupingMapString ) {
291293 var sql = ExpressionLambdaToSql ( exp , new ExpTSC { _tables = _tables , getSelectGroupingMapString = getSelectGroupingMapString , tbtype = SelectTableInfoType . From , isQuoteName = true , isDisableDiyParse = false , style = ExpressionStyle . Where } ) ;
294+ if ( exp . NodeType == ExpressionType . MemberAccess && exp . Type == typeof ( bool ) )
295+ return $ "{ sql } = { formatSql ( true , null ) } ";
292296 switch ( sql ) {
293297 case "1" :
294298 case "'t'" : return "1=1" ;
@@ -300,6 +304,8 @@ internal string ExpressionWhereLambda(List<SelectTableInfo> _tables, Expression
300304 internal void ExpressionJoinLambda ( List < SelectTableInfo > _tables , SelectTableInfoType tbtype , Expression exp , Func < Expression [ ] , string > getSelectGroupingMapString ) {
301305 var tbidx = _tables . Count ;
302306 var filter = ExpressionLambdaToSql ( exp , new ExpTSC { _tables = _tables , getSelectGroupingMapString = getSelectGroupingMapString , tbtype = tbtype , isQuoteName = true , isDisableDiyParse = false , style = ExpressionStyle . Where } ) ;
307+ if ( exp . NodeType == ExpressionType . MemberAccess && exp . Type == typeof ( bool ) )
308+ filter = $ "{ filter } = { formatSql ( true , null ) } ";
303309 switch ( filter ) {
304310 case "1" :
305311 case "'t'" : filter = "1=1" ; break ;
@@ -354,6 +360,23 @@ internal string ExpressionBinary(string oper, Expression leftExp, Expression rig
354360 }
355361 }
356362 }
363+ if ( leftExp . Type . NullableTypeOrThis ( ) == typeof ( bool ) && ( leftExp . NodeType != ExpressionType . MemberAccess && rightExp . NodeType != ExpressionType . MemberAccess ) ) {
364+ if ( oper == "=" ) {
365+ var trueVal = formatSql ( true , null ) ;
366+ var falseVal = formatSql ( false , null ) ;
367+ if ( left == trueVal ) return right ;
368+ else if ( left == falseVal ) return $ "not({ right } )";
369+ else if ( right == trueVal ) return left ;
370+ else if ( right == falseVal ) return $ "not({ left } )";
371+ } else if ( oper == "<>" ) {
372+ var trueVal = formatSql ( true , null ) ;
373+ var falseVal = formatSql ( false , null ) ;
374+ if ( left == trueVal ) return $ "not({ right } )";
375+ else if ( left == falseVal ) return right ;
376+ else if ( right == trueVal ) return $ "not({ left } )";
377+ else if ( right == falseVal ) return left ;
378+ }
379+ }
357380
358381 if ( left == "NULL" ) {
359382 var tmp = right ;
@@ -374,7 +397,10 @@ internal string ExpressionLambdaToSql(Expression exp, ExpTSC tsc) {
374397 if ( string . IsNullOrEmpty ( args . Result ) == false ) return args . Result ;
375398 }
376399 switch ( exp . NodeType ) {
377- case ExpressionType . Not : return $ "not({ ExpressionLambdaToSql ( ( exp as UnaryExpression ) ? . Operand , tsc ) } )";
400+ case ExpressionType . Not :
401+ var notExp = ( exp as UnaryExpression ) ? . Operand ;
402+ if ( notExp . NodeType == ExpressionType . MemberAccess ) return $ "{ ExpressionLambdaToSql ( notExp , tsc ) } = { formatSql ( false , null ) } ";
403+ return $ "not({ ExpressionLambdaToSql ( notExp , tsc ) } )";
378404 case ExpressionType . Quote : return ExpressionLambdaToSql ( ( exp as UnaryExpression ) ? . Operand , tsc ) ;
379405 case ExpressionType . Lambda : return ExpressionLambdaToSql ( ( exp as LambdaExpression ) ? . Body , tsc ) ;
380406 case ExpressionType . TypeAs :
0 commit comments