4
4
using System . Linq ;
5
5
using System . Linq . Expressions ;
6
6
using NHibernate . Linq ;
7
- using NHibernate . Util ;
8
7
using Remotion . Linq . Parsing . ExpressionVisitors ;
9
8
10
9
namespace NHibernate . Multi
11
10
{
11
+ interface ILinqBatchItem
12
+ {
13
+ List < TResult > GetTypedResults < TResult > ( ) ;
14
+ }
15
+
12
16
public static class LinqBatchItem
13
17
{
14
18
public static LinqBatchItem < TResult > Create < T , TResult > ( IQueryable < T > query , Expression < Func < IQueryable < T > , TResult > > selector )
@@ -42,9 +46,10 @@ private static LinqBatchItem<TResult> GetForQuery<TResult>(IQueryable query, Exp
42
46
/// Create instance via <see cref="LinqBatchItem.Create"/> methods
43
47
/// </summary>
44
48
/// <typeparam name="T">Result type</typeparam>
45
- public partial class LinqBatchItem < T > : QueryBatchItem < T >
49
+ public partial class LinqBatchItem < T > : QueryBatchItem < T > , ILinqBatchItem
46
50
{
47
51
private readonly Delegate _postExecuteTransformer ;
52
+ private readonly System . Type _resultTypeOverride ;
48
53
49
54
public LinqBatchItem ( IQuery query ) : base ( query )
50
55
{
@@ -53,6 +58,7 @@ public LinqBatchItem(IQuery query) : base(query)
53
58
internal LinqBatchItem ( IQuery query , NhLinqExpression linq ) : base ( query )
54
59
{
55
60
_postExecuteTransformer = linq . ExpressionToHqlTranslationResults . PostExecuteTransformer ;
61
+ _resultTypeOverride = linq . ExpressionToHqlTranslationResults . ExecuteResultTypeOverride ;
56
62
}
57
63
58
64
protected override IList < T > GetResultsNonBatched ( )
@@ -69,11 +75,10 @@ protected override List<T> DoGetResults()
69
75
{
70
76
if ( _postExecuteTransformer != null )
71
77
{
72
- var elementType = GetResultTypeIfChanged ( ) ;
73
-
74
- IList transformerList = elementType == null
78
+ IList transformerList = _resultTypeOverride == null
75
79
? base . DoGetResults ( )
76
- : GetTypedResults ( elementType ) ;
80
+ //see LinqToFutureValueFixture tests that cover this scenario
81
+ : LinqBatchReflectHelper . GetTypedResults ( this , _resultTypeOverride ) ;
77
82
78
83
return GetTransformedResults ( transformerList ) ;
79
84
}
@@ -90,27 +95,9 @@ private List<T> GetTransformedResults(IList transformerList)
90
95
} ;
91
96
}
92
97
93
- private System . Type GetResultTypeIfChanged ( )
94
- {
95
- if ( _postExecuteTransformer == null )
96
- {
97
- return null ;
98
- }
99
- var elementType = _postExecuteTransformer . Method . GetParameters ( ) [ 1 ] . ParameterType . GetGenericArguments ( ) [ 0 ] ;
100
- if ( typeof ( T ) . IsAssignableFrom ( elementType ) )
101
- {
102
- return null ;
103
- }
104
-
105
- return elementType ;
106
- }
107
-
108
- private IList GetTypedResults ( System . Type type )
98
+ List < TResult > ILinqBatchItem . GetTypedResults < TResult > ( )
109
99
{
110
- var method = ReflectHelper . GetMethod ( ( ) => GetTypedResults < T > ( ) )
111
- . GetGenericMethodDefinition ( ) ;
112
- var generic = method . MakeGenericMethod ( type ) ;
113
- return ( IList ) generic . Invoke ( this , null ) ;
100
+ return GetTypedResults < TResult > ( ) ;
114
101
}
115
102
}
116
103
}
0 commit comments