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)
7070 {
7171 var rawParameter = Visit ( expression . Arguments [ 0 ] ) ;
7272 // 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 ;
7474 var type = expression . Arguments [ 1 ] as ConstantExpression ;
7575 if ( parameter == null )
7676 throw new HibernateException (
@@ -83,7 +83,7 @@ protected override Expression VisitMethodCall(MethodCallExpression expression)
8383
8484 _parameters [ parameter ] . Type = ( IType ) type . Value ;
8585
86- return parameter ;
86+ return rawParameter ;
8787 }
8888
8989 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)
228228 if ( VisitorUtil . IsMappedAs ( node . Method ) )
229229 {
230230 var rawParameter = Visit ( node . Arguments [ 0 ] ) ;
231- var parameter = rawParameter as ConstantExpression ;
231+ var parameter = UnwrapUnary ( rawParameter ) as ConstantExpression ;
232232 var type = node . Arguments [ 1 ] as ConstantExpression ;
233233 if ( parameter == null )
234234 throw new HibernateException (
@@ -405,7 +405,7 @@ private bool IsDynamicMember(Expression expression)
405405 /// </summary>
406406 /// <param name="expression">The expression to unwrap.</param>
407407 /// <returns>The unwrapped expression.</returns>
408- private static Expression UnwrapUnary ( Expression expression )
408+ internal static Expression UnwrapUnary ( Expression expression )
409409 {
410410 while ( expression is UnaryExpression unaryExpression )
411411 {
You can’t perform that action at this time.
0 commit comments