@@ -151,7 +151,7 @@ private ICommandBuilder[] GetPagedQueryCommandBuilders(ref SimpleQuery query, In
151151 }
152152 else
153153 {
154- ApplyPaging ( commandBuilders , mainCommandBuilder , skipClause , takeClause , queryPager ) ;
154+ ApplyPaging ( commandBuilders , mainCommandBuilder , skipClause , takeClause , query . Clauses . OfType < WithClause > ( ) . Any ( ) , queryPager ) ;
155155 }
156156 }
157157 return commandBuilders . ToArray ( ) ;
@@ -168,21 +168,20 @@ private void DeferPaging(ref SimpleQuery query, ICommandBuilder mainCommandBuild
168168 commandBuilders . Add ( commandBuilder ) ;
169169 }
170170
171- private void ApplyPaging ( List < ICommandBuilder > commandBuilders , ICommandBuilder mainCommandBuilder , SkipClause skipClause ,
172- TakeClause takeClause , IQueryPager queryPager )
171+ private void ApplyPaging ( List < ICommandBuilder > commandBuilders , ICommandBuilder mainCommandBuilder , SkipClause skipClause , TakeClause takeClause , bool hasWithClause , IQueryPager queryPager )
173172 {
174173 const int maxInt = 2147483646 ;
175174
176175 IEnumerable < string > commandTexts ;
177- if ( skipClause == null )
176+ if ( skipClause == null && ! hasWithClause )
178177 {
179178 commandTexts = queryPager . ApplyLimit ( mainCommandBuilder . Text , takeClause . Count ) ;
180179 }
181180 else
182181 {
183- if ( takeClause == null ) takeClause = new TakeClause ( maxInt ) ;
184- commandTexts = queryPager . ApplyPaging ( mainCommandBuilder . Text , skipClause . Count ,
185- takeClause . Count ) ;
182+ int skip = skipClause == null ? 0 : skipClause . Count ;
183+ int take = takeClause == null ? maxInt : takeClause . Count ;
184+ commandTexts = queryPager . ApplyPaging ( mainCommandBuilder . Text , skip , take ) ;
186185 }
187186
188187 commandBuilders . AddRange (
0 commit comments