File tree Expand file tree Collapse file tree 3 files changed +53
-1
lines changed Expand file tree Collapse file tree 3 files changed +53
-1
lines changed Original file line number Diff line number Diff line change @@ -707,5 +707,30 @@ public async Task NullComparedToMemberInitExpressionInWhereClauseAsync()
707707
708708 Assert . That ( result . Count , Is . EqualTo ( 45 ) ) ;
709709 }
710+
711+ public class Specification < T >
712+ {
713+ private Expression < Func < T , bool > > _expression ;
714+
715+ public Specification ( Expression < Func < T , bool > > expression )
716+ {
717+ _expression = expression ;
718+ }
719+
720+ public static implicit operator Expression < Func < T , bool > > ( Specification < T > specification )
721+ {
722+ return specification . _expression ;
723+ }
724+ }
725+
726+ [ Test ]
727+ public async Task ImplicitConversionInsideWhereSubqueryExpressionAsync ( )
728+ {
729+ if ( ! Dialect . SupportsScalarSubSelects )
730+ Assert . Ignore ( Dialect . GetType ( ) . Name + " does not support scalar sub-queries" ) ;
731+
732+ var spec = new Specification < Order > ( x => x . Freight > 1000 ) ;
733+ await ( db . Orders . Where ( o => db . Orders . Where ( spec ) . Any ( x => x . OrderId == o . OrderId ) ) . ToListAsync ( ) ) ;
734+ }
710735 }
711736}
Original file line number Diff line number Diff line change @@ -788,5 +788,30 @@ public void NullComparedToMemberInitExpressionInWhereClause()
788788
789789 Assert . That ( result . Count , Is . EqualTo ( 45 ) ) ;
790790 }
791+
792+ public class Specification < T >
793+ {
794+ private Expression < Func < T , bool > > _expression ;
795+
796+ public Specification ( Expression < Func < T , bool > > expression )
797+ {
798+ _expression = expression ;
799+ }
800+
801+ public static implicit operator Expression < Func < T , bool > > ( Specification < T > specification )
802+ {
803+ return specification . _expression ;
804+ }
805+ }
806+
807+ [ Test ]
808+ public void ImplicitConversionInsideWhereSubqueryExpression ( )
809+ {
810+ if ( ! Dialect . SupportsScalarSubSelects )
811+ Assert . Ignore ( Dialect . GetType ( ) . Name + " does not support scalar sub-queries" ) ;
812+
813+ var spec = new Specification < Order > ( x => x . Freight > 1000 ) ;
814+ db . Orders . Where ( o => db . Orders . Where ( spec ) . Any ( x => x . OrderId == o . OrderId ) ) . ToList ( ) ;
815+ }
791816 }
792817}
Original file line number Diff line number Diff line change @@ -157,7 +157,9 @@ private Expression EvaluateSubtree(Expression subtree)
157157
158158 private bool ContainsVariable ( Expression expression )
159159 {
160- if ( ! ( expression is UnaryExpression unaryExpression ) )
160+ if ( ! ( expression is UnaryExpression unaryExpression ) ||
161+ // Avoid detecting expression variables as parameters
162+ typeof ( Expression ) . IsAssignableFrom ( expression . Type ) )
161163 {
162164 return false ;
163165 }
You can’t perform that action at this time.
0 commit comments