File tree 3 files changed +53
-1
lines changed
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()
707
707
708
708
Assert . That ( result . Count , Is . EqualTo ( 45 ) ) ;
709
709
}
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
+ }
710
735
}
711
736
}
Original file line number Diff line number Diff line change @@ -788,5 +788,30 @@ public void NullComparedToMemberInitExpressionInWhereClause()
788
788
789
789
Assert . That ( result . Count , Is . EqualTo ( 45 ) ) ;
790
790
}
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
+ }
791
816
}
792
817
}
Original file line number Diff line number Diff line change @@ -157,7 +157,9 @@ private Expression EvaluateSubtree(Expression subtree)
157
157
158
158
private bool ContainsVariable ( Expression expression )
159
159
{
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 ) )
161
163
{
162
164
return false ;
163
165
}
You can’t perform that action at this time.
0 commit comments