Skip to content

Commit e31aea3

Browse files
NH-3950 fix.
1 parent 49c82ea commit e31aea3

File tree

1 file changed

+34
-37
lines changed

1 file changed

+34
-37
lines changed

src/NHibernate/Impl/FutureValue.cs

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,44 @@
11
using System;
22
using System.Collections;
33
using System.Collections.Generic;
4+
using System.Linq;
45

56
namespace 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

Comments
 (0)