11using System ;
22using System . Collections ;
33using System . Collections . Generic ;
4+ using System . Linq ;
45
56namespace NHibernate . Impl
67{
7- internal class FutureValue < T > : IFutureValue < T > , IDelayedValue
8- {
9- public delegate IEnumerable < T > GetResult ( ) ;
10-
11- private readonly GetResult getResult ;
12-
13- public FutureValue ( GetResult result )
14- {
15- getResult = result ;
16- }
17-
18- public T Value
19- {
20- get
21- {
22- var result = getResult ( ) ;
8+ internal class FutureValue < T > : IFutureValue < T > , IDelayedValue
9+ {
10+ public delegate IEnumerable < T > GetResult ( ) ;
11+
12+ private readonly GetResult getResult ;
13+
14+ public FutureValue ( GetResult result )
15+ {
16+ getResult = result ;
17+ }
18+
19+ public T Value
20+ {
21+ get
22+ {
23+ var result = getResult ( ) ;
24+ if ( ExecuteOnEval != null )
25+ // When not null, ExecuteOnEval is fetched with PostExecuteTransformer from IntermediateHqlTree
26+ // through ExpressionToHqlTranslationResults, which requires a IQueryable as input and directly
27+ // yields the scalar result when the query is scalar.
28+ return ( T ) ExecuteOnEval . DynamicInvoke ( result . AsQueryable ( ) ) ;
29+
2330 var enumerator = result . GetEnumerator ( ) ;
2431
2532 if ( ! enumerator . MoveNext ( ) )
26- {
27- var defVal = default ( T ) ;
28- if ( ExecuteOnEval != null )
29- defVal = ( T ) ExecuteOnEval . DynamicInvoke ( defVal ) ;
30- return defVal ;
31- }
32-
33- var val = enumerator . Current ;
34-
35- if ( ExecuteOnEval != null )
36- val = ( T ) ExecuteOnEval . DynamicInvoke ( val ) ;
37-
38- return val ;
39- }
40- }
41-
42- public Delegate ExecuteOnEval
43- {
44- get ; set ;
45- }
46- }
33+ return default ( T ) ;
34+
35+ return enumerator . Current ;
36+ }
37+ }
38+
39+ public Delegate ExecuteOnEval
40+ {
41+ get ; set ;
42+ }
43+ }
4744}
0 commit comments