77using NHibernate . Exceptions ;
88using NHibernate . Hql ;
99using NHibernate . SqlCommand ;
10+ using NHibernate . Transform ;
1011using NHibernate . Type ;
1112
1213namespace NHibernate . Impl
@@ -39,7 +40,8 @@ public class EnumerableImpl : IEnumerable, IEnumerator, IDisposable
3940 // when we start enumerating through the DataReader we are positioned
4041 // before the first record we need
4142 private int _currentRow = - 1 ;
42- private HolderInstantiator _holderInstantiator ;
43+ private IResultTransformer _resultTransformer ;
44+ private string [ ] _returnAliases ;
4345 private RowSelection _selection ;
4446
4547 /// <summary>
@@ -56,6 +58,8 @@ public class EnumerableImpl : IEnumerable, IEnumerator, IDisposable
5658 /// <remarks>
5759 /// The <see cref="DbDataReader"/> should already be positioned on the first record in <see cref="RowSelection"/>.
5860 /// </remarks>
61+ //Since v5.2
62+ [ Obsolete ( "Please use the constructor accepting resultTransformer and queryReturnAliases" ) ]
5963 public EnumerableImpl ( DbDataReader reader ,
6064 DbCommand cmd ,
6165 IEventSource session ,
@@ -64,6 +68,35 @@ public EnumerableImpl(DbDataReader reader,
6468 string [ ] [ ] columnNames ,
6569 RowSelection selection ,
6670 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 )
67100 {
68101 _reader = reader ;
69102 _cmd = cmd ;
@@ -72,9 +105,10 @@ public EnumerableImpl(DbDataReader reader,
72105 _types = types ;
73106 _names = columnNames ;
74107 _selection = selection ;
75- _holderInstantiator = holderInstantiator ;
76108
77109 _single = _types . Length == 1 ;
110+ _resultTransformer = resultTransformer ;
111+ _returnAliases = returnAliases ;
78112 }
79113
80114 /// <summary>
@@ -179,9 +213,8 @@ private void PostMoveNext(bool hasNext)
179213 else
180214 {
181215 log . Debug ( "retrieving next results" ) ;
182- bool isHolder = _holderInstantiator . IsRequired ;
183-
184- if ( _single && ! isHolder )
216+
217+ if ( _single && _resultTransformer == null )
185218 {
186219 _currentResult = _types [ 0 ] . NullSafeGet ( _reader , _names [ 0 ] , _session , null ) ;
187220 }
@@ -199,10 +232,10 @@ private void PostMoveNext(bool hasNext)
199232 // and use the ISession to load an instance of the object.
200233 currentResults [ i ] = _types [ i ] . NullSafeGet ( _reader , _names [ i ] , _session , null ) ;
201234 }
202-
203- if ( isHolder )
235+
236+ if ( _resultTransformer != null )
204237 {
205- _currentResult = _holderInstantiator . Instantiate ( currentResults ) ;
238+ _currentResult = _resultTransformer . TransformTuple ( currentResults , _returnAliases ) ;
206239 }
207240 else
208241 {
0 commit comments