@@ -23,7 +23,7 @@ namespace NHibernate.Multi
23
23
{
24
24
using System . Threading . Tasks ;
25
25
using System . Threading ;
26
- public abstract partial class QueryBatchItemBase < TResult > : IQueryBatchItem < TResult >
26
+ public abstract partial class QueryBatchItemBase < TResult > : IQueryBatchItem < TResult > , IQueryBatchItemWithAsyncProcessResults
27
27
{
28
28
29
29
/// <inheritdoc />
@@ -103,17 +103,46 @@ public async Task<int> ProcessResultsSetAsync(DbDataReader reader, CancellationT
103
103
104
104
queryInfo . Result = tmpResults ;
105
105
if ( queryInfo . CanPutToCache )
106
- queryInfo . ResultToCache = tmpResults ;
106
+ queryInfo . ResultToCache = new List < object > ( tmpResults ) ;
107
107
108
108
await ( reader . NextResultAsync ( cancellationToken ) ) . ConfigureAwait ( false ) ;
109
109
}
110
110
111
- await ( InitializeEntitiesAndCollectionsAsync ( reader , hydratedObjects , cancellationToken ) ) . ConfigureAwait ( false ) ;
112
-
111
+ StopLoadingCollections ( reader ) ;
112
+ _reader = reader ;
113
+ _hydratedObjects = hydratedObjects ;
113
114
return rowCount ;
114
115
}
115
116
}
116
117
118
+ /// <inheritdoc cref="IQueryBatchItem.ProcessResults" />
119
+ public async Task ProcessResultsAsync ( CancellationToken cancellationToken )
120
+ {
121
+ cancellationToken . ThrowIfCancellationRequested ( ) ;
122
+ ThrowIfNotInitialized ( ) ;
123
+
124
+ using ( Session . SwitchCacheMode ( _cacheMode ) )
125
+ await ( InitializeEntitiesAndCollectionsAsync ( _reader , _hydratedObjects , cancellationToken ) ) . ConfigureAwait ( false ) ;
126
+
127
+ for ( var i = 0 ; i < _queryInfos . Count ; i ++ )
128
+ {
129
+ var queryInfo = _queryInfos [ i ] ;
130
+ if ( _subselectResultKeys [ i ] != null )
131
+ {
132
+ queryInfo . Loader . CreateSubselects ( _subselectResultKeys [ i ] , queryInfo . Parameters , Session ) ;
133
+ }
134
+
135
+ if ( queryInfo . IsCacheable )
136
+ {
137
+ // This transformation must not be applied to ResultToCache.
138
+ queryInfo . Result =
139
+ queryInfo . Loader . TransformCacheableResults (
140
+ queryInfo . Parameters , queryInfo . CacheKey . ResultTransformer , queryInfo . Result ) ;
141
+ }
142
+ }
143
+ AfterLoadCallback ? . Invoke ( GetResults ( ) ) ;
144
+ }
145
+
117
146
/// <inheritdoc />
118
147
public async Task ExecuteNonBatchedAsync ( CancellationToken cancellationToken )
119
148
{
0 commit comments