File tree Expand file tree Collapse file tree 4 files changed +97
-4
lines changed Expand file tree Collapse file tree 4 files changed +97
-4
lines changed Original file line number Diff line number Diff line change
1
+ //------------------------------------------------------------------------------
2
+ // <auto-generated>
3
+ // This code was generated by AsyncGenerator.
4
+ //
5
+ // Changes to this file may cause incorrect behavior and will be lost if
6
+ // the code is regenerated.
7
+ // </auto-generated>
8
+ //------------------------------------------------------------------------------
9
+
10
+
11
+ using System ;
12
+ using System . Collections . Generic ;
13
+ using System . Linq ;
14
+ using System . Text ;
15
+ using NHibernate . Linq ;
16
+ using NUnit . Framework ;
17
+
18
+ namespace NHibernate . Test . Linq . ByMethod
19
+ {
20
+ using System . Threading . Tasks ;
21
+ [ TestFixture ]
22
+ public class MappedAsTestsAsync : LinqTestCase
23
+ {
24
+ [ Test ]
25
+ public async Task WithUnaryExpressionAsync ( )
26
+ {
27
+ var num = 1 ;
28
+ await ( db . Orders . Where ( o => o . Freight == ( - num ) . MappedAs ( NHibernateUtil . Decimal ) ) . ToListAsync ( ) ) ;
29
+ await ( db . Orders . Where ( o => o . Freight == ( ( decimal ) num ) . MappedAs ( NHibernateUtil . Decimal ) ) . ToListAsync ( ) ) ;
30
+ await ( db . Orders . Where ( o => o . Freight == ( ( decimal ? ) ( decimal ) num ) . MappedAs ( NHibernateUtil . Decimal ) ) . ToListAsync ( ) ) ;
31
+ }
32
+
33
+ [ Test ]
34
+ public async Task WithNewExpressionAsync ( )
35
+ {
36
+ var num = 1 ;
37
+ await ( db . Orders . Where ( o => o . Freight == new decimal ( num ) . MappedAs ( NHibernateUtil . Decimal ) ) . ToListAsync ( ) ) ;
38
+ }
39
+
40
+ [ Test ]
41
+ public async Task WithMethodCallExpressionAsync ( )
42
+ {
43
+ var num = 1 ;
44
+ await ( db . Orders . Where ( o => o . Freight == GetDecimal ( num ) . MappedAs ( NHibernateUtil . Decimal ) ) . ToListAsync ( ) ) ;
45
+ }
46
+
47
+ private decimal GetDecimal ( int number )
48
+ {
49
+ return number ;
50
+ }
51
+ }
52
+ }
Original file line number Diff line number Diff line change
1
+ using System ;
2
+ using System . Collections . Generic ;
3
+ using System . Linq ;
4
+ using System . Text ;
5
+ using NHibernate . Linq ;
6
+ using NUnit . Framework ;
7
+
8
+ namespace NHibernate . Test . Linq . ByMethod
9
+ {
10
+ [ TestFixture ]
11
+ public class MappedAsTests : LinqTestCase
12
+ {
13
+ [ Test ]
14
+ public void WithUnaryExpression ( )
15
+ {
16
+ var num = 1 ;
17
+ db . Orders . Where ( o => o . Freight == ( - num ) . MappedAs ( NHibernateUtil . Decimal ) ) . ToList ( ) ;
18
+ db . Orders . Where ( o => o . Freight == ( ( decimal ) num ) . MappedAs ( NHibernateUtil . Decimal ) ) . ToList ( ) ;
19
+ db . Orders . Where ( o => o . Freight == ( ( decimal ? ) ( decimal ) num ) . MappedAs ( NHibernateUtil . Decimal ) ) . ToList ( ) ;
20
+ }
21
+
22
+ [ Test ]
23
+ public void WithNewExpression ( )
24
+ {
25
+ var num = 1 ;
26
+ db . Orders . Where ( o => o . Freight == new decimal ( num ) . MappedAs ( NHibernateUtil . Decimal ) ) . ToList ( ) ;
27
+ }
28
+
29
+ [ Test ]
30
+ public void WithMethodCallExpression ( )
31
+ {
32
+ var num = 1 ;
33
+ db . Orders . Where ( o => o . Freight == GetDecimal ( num ) . MappedAs ( NHibernateUtil . Decimal ) ) . ToList ( ) ;
34
+ }
35
+
36
+ private decimal GetDecimal ( int number )
37
+ {
38
+ return number ;
39
+ }
40
+ }
41
+ }
Original file line number Diff line number Diff line change @@ -70,7 +70,7 @@ protected override Expression VisitMethodCall(MethodCallExpression expression)
70
70
{
71
71
var rawParameter = Visit ( expression . Arguments [ 0 ] ) ;
72
72
// TODO 6.0: Remove below code and return expression as this logic is now inside ConstantTypeLocator
73
- var parameter = rawParameter as ConstantExpression ;
73
+ var parameter = ParameterTypeLocator . UnwrapUnary ( rawParameter ) as ConstantExpression ;
74
74
var type = expression . Arguments [ 1 ] as ConstantExpression ;
75
75
if ( parameter == null )
76
76
throw new HibernateException (
@@ -83,7 +83,7 @@ protected override Expression VisitMethodCall(MethodCallExpression expression)
83
83
84
84
_parameters [ parameter ] . Type = ( IType ) type . Value ;
85
85
86
- return parameter ;
86
+ return rawParameter ;
87
87
}
88
88
89
89
var method = expression . Method . IsGenericMethod
Original file line number Diff line number Diff line change @@ -228,7 +228,7 @@ protected override Expression VisitMethodCall(MethodCallExpression node)
228
228
if ( VisitorUtil . IsMappedAs ( node . Method ) )
229
229
{
230
230
var rawParameter = Visit ( node . Arguments [ 0 ] ) ;
231
- var parameter = rawParameter as ConstantExpression ;
231
+ var parameter = UnwrapUnary ( rawParameter ) as ConstantExpression ;
232
232
var type = node . Arguments [ 1 ] as ConstantExpression ;
233
233
if ( parameter == null )
234
234
throw new HibernateException (
@@ -405,7 +405,7 @@ private bool IsDynamicMember(Expression expression)
405
405
/// </summary>
406
406
/// <param name="expression">The expression to unwrap.</param>
407
407
/// <returns>The unwrapped expression.</returns>
408
- private static Expression UnwrapUnary ( Expression expression )
408
+ internal static Expression UnwrapUnary ( Expression expression )
409
409
{
410
410
while ( expression is UnaryExpression unaryExpression )
411
411
{
You can’t perform that action at this time.
0 commit comments