7
7
using NHibernate . Exceptions ;
8
8
using NHibernate . Hql ;
9
9
using NHibernate . SqlCommand ;
10
+ using NHibernate . Transform ;
10
11
using NHibernate . Type ;
11
12
12
13
namespace NHibernate . Impl
@@ -39,7 +40,8 @@ public class EnumerableImpl : IEnumerable, IEnumerator, IDisposable
39
40
// when we start enumerating through the DataReader we are positioned
40
41
// before the first record we need
41
42
private int _currentRow = - 1 ;
42
- private HolderInstantiator _holderInstantiator ;
43
+ private IResultTransformer _resultTransformer ;
44
+ private string [ ] _returnAliases ;
43
45
private RowSelection _selection ;
44
46
45
47
/// <summary>
@@ -56,6 +58,8 @@ public class EnumerableImpl : IEnumerable, IEnumerator, IDisposable
56
58
/// <remarks>
57
59
/// The <see cref="DbDataReader"/> should already be positioned on the first record in <see cref="RowSelection"/>.
58
60
/// </remarks>
61
+ //Since v5.2
62
+ [ Obsolete ( "Please use the constructor accepting resultTransformer and queryReturnAliases" ) ]
59
63
public EnumerableImpl ( DbDataReader reader ,
60
64
DbCommand cmd ,
61
65
IEventSource session ,
@@ -64,6 +68,35 @@ public EnumerableImpl(DbDataReader reader,
64
68
string [ ] [ ] columnNames ,
65
69
RowSelection selection ,
66
70
HolderInstantiator holderInstantiator )
71
+ : this ( reader , cmd , session , readOnly , types , columnNames , selection , holderInstantiator . ResultTransformer , holderInstantiator . QueryReturnAliases )
72
+ {
73
+ }
74
+
75
+ /// <summary>
76
+ /// Create an <see cref="IEnumerable"/> wrapper over an <see cref="DbDataReader"/>.
77
+ /// </summary>
78
+ /// <param name="reader">The <see cref="DbDataReader"/> to enumerate over.</param>
79
+ /// <param name="cmd">The <see cref="DbCommand"/> used to create the <see cref="DbDataReader"/>.</param>
80
+ /// <param name="session">The <see cref="ISession"/> to use to load objects.</param>
81
+ /// <param name="readOnly"></param>
82
+ /// <param name="types">The <see cref="IType"/>s contained in the <see cref="DbDataReader"/>.</param>
83
+ /// <param name="columnNames">The names of the columns in the <see cref="DbDataReader"/>.</param>
84
+ /// <param name="selection">The <see cref="RowSelection"/> that should be applied to the <see cref="DbDataReader"/>.</param>
85
+ /// <param name="resultTransformer">The <see cref="IResultTransformer"/> that should be applied to a result row or <c>null</c>.</param>
86
+ /// <param name="returnAliases">The aliases that correspond to a result row.</param>
87
+ /// <remarks>
88
+ /// The <see cref="DbDataReader"/> should already be positioned on the first record in <see cref="RowSelection"/>.
89
+ /// </remarks>
90
+ public EnumerableImpl (
91
+ DbDataReader reader ,
92
+ DbCommand cmd ,
93
+ IEventSource session ,
94
+ bool readOnly ,
95
+ IType [ ] types ,
96
+ string [ ] [ ] columnNames ,
97
+ RowSelection selection ,
98
+ IResultTransformer resultTransformer ,
99
+ string [ ] returnAliases )
67
100
{
68
101
_reader = reader ;
69
102
_cmd = cmd ;
@@ -72,9 +105,10 @@ public EnumerableImpl(DbDataReader reader,
72
105
_types = types ;
73
106
_names = columnNames ;
74
107
_selection = selection ;
75
- _holderInstantiator = holderInstantiator ;
76
108
77
109
_single = _types . Length == 1 ;
110
+ _resultTransformer = resultTransformer ;
111
+ _returnAliases = returnAliases ;
78
112
}
79
113
80
114
/// <summary>
@@ -179,9 +213,8 @@ private void PostMoveNext(bool hasNext)
179
213
else
180
214
{
181
215
log . Debug ( "retrieving next results" ) ;
182
- bool isHolder = _holderInstantiator . IsRequired ;
183
-
184
- if ( _single && ! isHolder )
216
+
217
+ if ( _single && _resultTransformer == null )
185
218
{
186
219
_currentResult = _types [ 0 ] . NullSafeGet ( _reader , _names [ 0 ] , _session , null ) ;
187
220
}
@@ -199,10 +232,10 @@ private void PostMoveNext(bool hasNext)
199
232
// and use the ISession to load an instance of the object.
200
233
currentResults [ i ] = _types [ i ] . NullSafeGet ( _reader , _names [ i ] , _session , null ) ;
201
234
}
202
-
203
- if ( isHolder )
235
+
236
+ if ( _resultTransformer != null )
204
237
{
205
- _currentResult = _holderInstantiator . Instantiate ( currentResults ) ;
238
+ _currentResult = _resultTransformer . TransformTuple ( currentResults , _returnAliases ) ;
206
239
}
207
240
else
208
241
{
0 commit comments