@@ -44,6 +44,9 @@ public async Task<LoadResult> LoadAsync() {
4444 if ( Context . IsCountQuery )
4545 return new LoadResult { totalCount = await ExecTotalCountAsync ( ) } ;
4646
47+ if ( Context . Take < 0 )
48+ return await LoadAggregatesOnlyAsync ( ) ;
49+
4750 var result = new LoadResult ( ) ;
4851
4952 if ( Context . UseRemoteGrouping && Context . ShouldEmptyGroups ) {
@@ -116,6 +119,21 @@ await ExecExprAsync<S>(loadExpr),
116119 return result ;
117120 }
118121
122+ async Task < LoadResult > LoadAggregatesOnlyAsync ( ) {
123+ var result = new LoadResult ( ) ;
124+
125+ if ( Context . HasTotalSummary ) {
126+ if ( Context . IsRemoteTotalSummary ) {
127+ await ContinueWithAggregationAsync < S > ( null , null , result , false ) ;
128+ } else {
129+ var data = await ExecExprAsync < S > ( CreateBuilder ( ) . BuildLoadExpr ( false ) ) ;
130+ await ContinueWithAggregationAsync ( data , new DefaultAccessor < S > ( ) , result , false ) ;
131+ }
132+ }
133+
134+ return result ;
135+ }
136+
119137 async Task < IEnumerable < ExpandoObject > > ExecWithSelectAsync ( Expression loadExpr ) {
120138 if ( Context . UseRemoteSelect )
121139 return SelectHelper . ConvertRemoteResult ( await ExecExprAnonAsync ( loadExpr ) , Context . FullSelect ) ;
@@ -129,14 +147,14 @@ async Task ContinueWithGroupingAsync<R>(IEnumerable<R> loadResult, LoadResult re
129147 var groups = new GroupHelper < R > ( accessor ) . Group ( loadResult , Context . Group ) ;
130148 if ( Context . RequireGroupCount )
131149 result . groupCount = groups . Count ;
132- await ContinueWithAggregationAsync ( groups , accessor , result ) ;
150+ await ContinueWithAggregationAsync ( groups , accessor , result , true ) ;
133151 } else {
134- await ContinueWithAggregationAsync ( loadResult , accessor , result ) ;
152+ await ContinueWithAggregationAsync ( loadResult , accessor , result , true ) ;
135153 }
136154 }
137155
138- async Task ContinueWithAggregationAsync < R > ( IEnumerable data , IAccessor < R > accessor , LoadResult result ) {
139- if ( Context . UseRemoteGrouping && ! Context . SummaryIsTotalCountOnly && Context . HasSummary && ! Context . HasGroups ) {
156+ async Task ContinueWithAggregationAsync < R > ( IEnumerable data , IAccessor < R > accessor , LoadResult result , bool includeData ) {
157+ if ( Context . IsRemoteTotalSummary ) {
140158 var totalsResult = await ExecRemoteTotalsAsync ( ) ;
141159 result . totalCount = totalsResult . TotalCount ;
142160 result . summary = totalsResult . Totals ;
@@ -152,12 +170,14 @@ async Task ContinueWithAggregationAsync<R>(IEnumerable data, IAccessor<R> access
152170 if ( Context . SummaryIsTotalCountOnly ) {
153171 result . summary = Enumerable . Repeat ( ( object ) totalCount , Context . TotalSummary . Count ) . ToArray ( ) ;
154172 } else if ( Context . HasSummary ) {
155- data = Buffer < R > ( data ) ;
173+ if ( includeData )
174+ data = Buffer < R > ( data ) ;
156175 result . summary = new AggregateCalculator < R > ( data , accessor , Context . TotalSummary , Context . GroupSummary ) . Run ( ) ;
157176 }
158177 }
159178
160- result . data = data ;
179+ if ( includeData )
180+ result . data = data ;
161181 }
162182
163183 Task < int > ExecCountAsync ( Expression expr ) {
0 commit comments