@@ -17,13 +17,13 @@ public static partial class QueryBatchExtensions
1717 /// </summary>
1818 /// <param name="batch">The batch.</param>
1919 /// <param name="query">The query.</param>
20+ /// <param name="afterLoad">Callback to execute when query is loaded. Loaded results are provided as action parameter.</param>
2021 /// <exception cref="InvalidOperationException">Thrown if the batch has already been executed.</exception>
2122 /// <exception cref="ArgumentNullException">Thrown if <paramref name="query"/> is <see langword="null"/>.</exception>
2223 /// <returns>The batch instance for method chain.</returns>
23- public static IQueryBatch Add < TResult > ( this IQueryBatch batch , IQueryOver query )
24+ public static IQueryBatch Add < TResult > ( this IQueryBatch batch , IQueryOver query , Action < IList < TResult > > afterLoad = null )
2425 {
25- batch . Add ( For < TResult > ( query ) ) ;
26- return batch ;
26+ return batch . Add ( For < TResult > ( query ) , afterLoad ) ;
2727 }
2828
2929 /// <summary>
@@ -48,13 +48,13 @@ public static IQueryBatch Add<TResult>(this IQueryBatch batch, string key, IQuer
4848 /// </summary>
4949 /// <param name="batch">The batch.</param>
5050 /// <param name="query">The query.</param>
51+ /// <param name="afterLoad">Callback to execute when query is loaded. Loaded results are provided as action parameter.</param>
5152 /// <exception cref="InvalidOperationException">Thrown if the batch has already been executed.</exception>
5253 /// <exception cref="ArgumentNullException">Thrown if <paramref name="query"/> is <see langword="null"/>.</exception>
5354 /// <returns>The batch instance for method chain.</returns>
54- public static IQueryBatch Add < TResult > ( this IQueryBatch batch , IQueryOver < TResult > query )
55+ public static IQueryBatch Add < TResult > ( this IQueryBatch batch , IQueryOver < TResult > query , Action < IList < TResult > > afterLoad = null )
5556 {
56- batch . Add ( For < TResult > ( query ) ) ;
57- return batch ;
57+ return batch . Add ( For < TResult > ( query ) , afterLoad ) ;
5858 }
5959
6060 /// <summary>
@@ -77,13 +77,13 @@ public static IQueryBatch Add<TResult>(this IQueryBatch batch, string key, IQuer
7777 /// </summary>
7878 /// <param name="batch">The batch.</param>
7979 /// <param name="query">The query.</param>
80+ /// <param name="afterLoad">Callback to execute when query is loaded. Loaded results are provided as action parameter.</param>
8081 /// <exception cref="InvalidOperationException">Thrown if the batch has already been executed.</exception>
8182 /// <exception cref="ArgumentNullException">Thrown if <paramref name="query"/> is <see langword="null"/>.</exception>
8283 /// <returns>The batch instance for method chain.</returns>
83- public static IQueryBatch Add < TResult > ( this IQueryBatch batch , ICriteria query )
84+ public static IQueryBatch Add < TResult > ( this IQueryBatch batch , ICriteria query , Action < IList < TResult > > afterLoad = null )
8485 {
85- batch . Add ( For < TResult > ( query ) ) ;
86- return batch ;
86+ return batch . Add ( For < TResult > ( query ) , afterLoad ) ;
8787 }
8888
8989 /// <summary>
@@ -106,13 +106,13 @@ public static IQueryBatch Add<TResult>(this IQueryBatch batch, string key, ICrit
106106 /// </summary>
107107 /// <param name="batch">The batch.</param>
108108 /// <param name="query">The query.</param>
109+ /// <param name="afterLoad">Callback to execute when query is loaded. Loaded results are provided as action parameter.</param>
109110 /// <exception cref="InvalidOperationException">Thrown if the batch has already been executed.</exception>
110111 /// <exception cref="ArgumentNullException">Thrown if <paramref name="query"/> is <see langword="null"/>.</exception>
111112 /// <returns>The batch instance for method chain.</returns>
112- public static IQueryBatch Add < TResult > ( this IQueryBatch batch , DetachedCriteria query )
113+ public static IQueryBatch Add < TResult > ( this IQueryBatch batch , DetachedCriteria query , Action < IList < TResult > > afterLoad = null )
113114 {
114- batch . Add ( For < TResult > ( query ) ) ;
115- return batch ;
115+ return batch . Add ( For < TResult > ( query ) , afterLoad ) ;
116116 }
117117
118118 /// <summary>
@@ -135,13 +135,13 @@ public static IQueryBatch Add<TResult>(this IQueryBatch batch, string key, Detac
135135 /// </summary>
136136 /// <param name="batch">The batch.</param>
137137 /// <param name="query">The query.</param>
138+ /// <param name="afterLoad">Callback to execute when query is loaded. Loaded results are provided as action parameter.</param>
138139 /// <exception cref="InvalidOperationException">Thrown if the batch has already been executed.</exception>
139140 /// <exception cref="ArgumentNullException">Thrown if <paramref name="query"/> is <see langword="null"/>.</exception>
140141 /// <returns>The batch instance for method chain.</returns>
141- public static IQueryBatch Add < TResult > ( this IQueryBatch batch , IQuery query )
142+ public static IQueryBatch Add < TResult > ( this IQueryBatch batch , IQuery query , Action < IList < TResult > > afterLoad = null )
142143 {
143- batch . Add ( For < TResult > ( query ) ) ;
144- return batch ;
144+ return batch . Add ( For < TResult > ( query ) , afterLoad ) ;
145145 }
146146
147147 /// <summary>
@@ -164,13 +164,13 @@ public static IQueryBatch Add<TResult>(this IQueryBatch batch, string key, IQuer
164164 /// </summary>
165165 /// <param name="batch">The batch.</param>
166166 /// <param name="query">The query.</param>
167+ /// <param name="afterLoad">Callback to execute when query is loaded. Loaded results are provided as action parameter.</param>
167168 /// <exception cref="InvalidOperationException">Thrown if the batch has already been executed.</exception>
168169 /// <exception cref="ArgumentNullException">Thrown if <paramref name="query"/> is <see langword="null"/>.</exception>
169170 /// <returns>The batch instance for method chain.</returns>
170- public static IQueryBatch Add < TResult > ( this IQueryBatch batch , IQueryable < TResult > query )
171+ public static IQueryBatch Add < TResult > ( this IQueryBatch batch , IQueryable < TResult > query , Action < IList < TResult > > afterLoad = null )
171172 {
172- batch . Add ( For ( query ) ) ;
173- return batch ;
173+ return batch . Add ( For < TResult > ( query ) , afterLoad ) ;
174174 }
175175
176176 /// <summary>
@@ -188,6 +188,37 @@ public static IQueryBatch Add<TResult>(this IQueryBatch batch, string key, IQuer
188188 return batch ;
189189 }
190190
191+ /// <summary>
192+ /// Adds a query to the batch.
193+ /// </summary>
194+ /// <param name="batch">The batch.</param>
195+ /// <param name="query">The query.</param>
196+ /// <param name="selector">An aggregation function to apply to <paramref name="query"/>.</param>
197+ /// <param name="afterLoad">Callback to execute when query is loaded. Loaded results are provided as action parameter.</param>
198+ /// <exception cref="InvalidOperationException">Thrown if the batch has already been executed.</exception>
199+ /// <exception cref="ArgumentNullException">Thrown if <paramref name="query"/> is <see langword="null"/>.</exception>
200+ /// <returns>The batch instance for method chain.</returns>
201+ public static IQueryBatch Add < TSource , TResult > ( this IQueryBatch batch , IQueryable < TSource > query , Expression < Func < IQueryable < TSource > , TResult > > selector , Action < TResult > afterLoad = null )
202+ {
203+ return batch . Add ( For ( query , selector ) , afterLoad == null ? ( Action < IList < TResult > > ) null : list => afterLoad ( list . FirstOrDefault ( ) ) ) ;
204+ }
205+
206+ /// <summary>
207+ /// Adds a query to the batch.
208+ /// </summary>
209+ /// <param name="batch">The batch.</param>
210+ /// <param name="key">A key for retrieval of the query result.</param>
211+ /// <param name="query">The query.</param>
212+ /// <param name="selector">An aggregation function to apply to <paramref name="query"/>.</param>
213+ /// <exception cref="InvalidOperationException">Thrown if the batch has already been executed.</exception>
214+ /// <exception cref="ArgumentNullException">Thrown if <paramref name="query"/> is <see langword="null"/>.</exception>
215+ /// <returns>The batch instance for method chain.</returns>
216+ public static IQueryBatch Add < TSource , TResult > ( this IQueryBatch batch , string key , IQueryable < TSource > query , Expression < Func < IQueryable < TSource > , TResult > > selector )
217+ {
218+ batch . Add ( key , For ( query , selector ) ) ;
219+ return batch ;
220+ }
221+
191222 /// <summary>
192223 /// Sets the timeout in seconds for the underlying ADO.NET query.
193224 /// </summary>
@@ -324,6 +355,16 @@ private static CriteriaBatchItem<TResult> For<TResult>(IQueryOver query)
324355 return For < TResult > ( query . RootCriteria ) ;
325356 }
326357
358+ private static IQueryBatch Add < TResult > ( this IQueryBatch batch , IQueryBatchItem < TResult > query , Action < IList < TResult > > afterLoad )
359+ {
360+ if ( afterLoad != null )
361+ {
362+ query . OnAfterLoad += afterLoad ;
363+ }
364+ batch . Add ( query ) ;
365+ return batch ;
366+ }
367+
327368 #region Helper classes
328369
329370 partial class FutureValue < TResult > : IFutureValue < TResult >
0 commit comments