File tree 3 files changed +40
-6
lines changed
3 files changed +40
-6
lines changed Original file line number Diff line number Diff line change @@ -125,6 +125,23 @@ public async Task UsingValueTypeParameterTwiceAsync()
125
125
1 ) ) ;
126
126
}
127
127
128
+ [ Test ]
129
+ public async Task UsingParameterInEvaluatableExpressionAsync ( )
130
+ {
131
+ var value = "test" ;
132
+ await ( db . Orders . Where ( o => string . Format ( "{0}" , value ) != o . ShippedTo ) . ToListAsync ( ) ) ;
133
+ await ( db . Orders . Where ( o => $ "{ value } _" != o . ShippedTo ) . ToListAsync ( ) ) ;
134
+ await ( db . Orders . Where ( o => string . Copy ( value ) != o . ShippedTo ) . ToListAsync ( ) ) ;
135
+
136
+ var guid = Guid . Parse ( "2D7E6EB3-BD08-4A40-A4E7-5150F7895821" ) ;
137
+ await ( db . Orders . Where ( o => o . ShippedTo . Contains ( $ "VALUE { guid } ") ) . ToListAsync ( ) ) ;
138
+
139
+ var names = new [ ] { "name" } ;
140
+ await ( db . Users . Where ( x => names . Length == 0 || names . Contains ( x . Name ) ) . ToListAsync ( ) ) ;
141
+ names = new string [ ] { } ;
142
+ await ( db . Users . Where ( x => names . Length == 0 || names . Contains ( x . Name ) ) . ToListAsync ( ) ) ;
143
+ }
144
+
128
145
[ Test ]
129
146
public async Task UsingNegateValueTypeParameterTwiceAsync ( )
130
147
{
Original file line number Diff line number Diff line change @@ -113,6 +113,23 @@ public void UsingValueTypeParameterTwice()
113
113
1 ) ;
114
114
}
115
115
116
+ [ Test ]
117
+ public void UsingParameterInEvaluatableExpression ( )
118
+ {
119
+ var value = "test" ;
120
+ db . Orders . Where ( o => string . Format ( "{0}" , value ) != o . ShippedTo ) . ToList ( ) ;
121
+ db . Orders . Where ( o => $ "{ value } _" != o . ShippedTo ) . ToList ( ) ;
122
+ db . Orders . Where ( o => string . Copy ( value ) != o . ShippedTo ) . ToList ( ) ;
123
+
124
+ var guid = Guid . Parse ( "2D7E6EB3-BD08-4A40-A4E7-5150F7895821" ) ;
125
+ db . Orders . Where ( o => o . ShippedTo . Contains ( $ "VALUE { guid } ") ) . ToList ( ) ;
126
+
127
+ var names = new [ ] { "name" } ;
128
+ db . Users . Where ( x => names . Length == 0 || names . Contains ( x . Name ) ) . ToList ( ) ;
129
+ names = new string [ ] { } ;
130
+ db . Users . Where ( x => names . Length == 0 || names . Contains ( x . Name ) ) . ToList ( ) ;
131
+ }
132
+
116
133
[ Test ]
117
134
public void ValidateMixingTwoParametersCacheKeys ( )
118
135
{
Original file line number Diff line number Diff line change @@ -77,7 +77,12 @@ public override Expression Visit(Expression expression)
77
77
if ( expression == null )
78
78
return null ;
79
79
80
- if ( expression . NodeType == ExpressionType . Lambda || ! _partialEvaluationInfo . IsEvaluatableExpression ( expression ) )
80
+ if ( expression . NodeType == ExpressionType . Lambda || ! _partialEvaluationInfo . IsEvaluatableExpression ( expression ) ||
81
+ #region NH additions
82
+ // Variables should be evaluated only when they are part of an evaluatable expression (e.g. o => string.Format("...", variable))
83
+ expression is UnaryExpression unaryExpression &&
84
+ ExpressionsHelper . IsVariable ( unaryExpression . Operand , out _ , out _ ) )
85
+ #endregion
81
86
return base . Visit ( expression ) ;
82
87
83
88
Expression evaluatedExpression ;
@@ -211,11 +216,6 @@ public override bool IsEvaluatableConstant(ConstantExpression node)
211
216
return base . IsEvaluatableConstant ( node ) ;
212
217
}
213
218
214
- public override bool IsEvaluatableUnary ( UnaryExpression node )
215
- {
216
- return ! ExpressionsHelper . IsVariable ( node . Operand , out _ , out _ ) ;
217
- }
218
-
219
219
public override bool IsEvaluatableMember ( MemberExpression node )
220
220
{
221
221
if ( node == null )
You can’t perform that action at this time.
0 commit comments