99
1010 using Community . OData . Linq . Builder ;
1111 using Community . OData . Linq . Builder . Validators ;
12+ using Community . OData . Linq . Common ;
1213 using Community . OData . Linq . OData ;
1314 using Community . OData . Linq . OData . Query ;
14- using Community . OData . Linq . OData . Query . Expressions ;
15+ using Community . OData . Linq . OData . Query . Expressions ;
16+ using Community . OData . Linq . Properties ;
1517
1618 using Microsoft . Extensions . DependencyInjection ;
1719 using Microsoft . OData ;
@@ -127,28 +129,72 @@ public static IEnumerable<ISelectExpandWrapper> SelectExpand<T>(
127129 return Enumerate < ISelectExpandWrapper > ( result ) ;
128130 }
129131
132+ public static ODataQuery < T > TopSkip < T > ( this ODataQuery < T > query , string topText = null , string skipText = null , string entitySetName = null )
133+ {
134+ if ( query == null ) throw new ArgumentNullException ( nameof ( query ) ) ;
135+
136+ ODataSettings settings = query . ServiceProvider . GetRequiredService < ODataSettings > ( ) ;
137+
138+ Dictionary < string , string > dictionary = new Dictionary < string , string > ( ) ;
139+
140+ if ( topText != null )
141+ {
142+ dictionary . Add ( "$top" , topText ) ;
143+ }
144+
145+ if ( skipText != null )
146+ {
147+ dictionary . Add ( "$skip" , skipText ) ;
148+ }
149+
150+ ODataQueryOptionParser queryOptionParser = GetParser (
151+ query ,
152+ entitySetName ,
153+ dictionary ) ;
154+
155+ long ? skip = queryOptionParser . ParseSkip ( ) ;
156+ long ? top = queryOptionParser . ParseTop ( ) ;
157+
158+ if ( skip . HasValue || top . HasValue || settings . QuerySettings . PageSize . HasValue )
159+ {
160+ IQueryable < T > result = TopSkipHelper . ApplySkipWithValidation ( query , skip , settings ) ;
161+ if ( top . HasValue )
162+ {
163+ result = TopSkipHelper . ApplyTopWithValidation ( result , top , settings ) ;
164+ }
165+ else
166+ {
167+ result = TopSkipHelper . ApplyTopWithValidation ( result , settings . QuerySettings . PageSize , settings ) ;
168+ }
169+
170+ return new ODataQuery < T > ( result , query . ServiceProvider ) ;
171+ }
172+
173+ return query ;
174+ }
175+
130176 /// <summary>
131- /// The Filter.
132- /// </summary>
133- /// <param name="query">
134- /// The OData aware query.
135- /// </param>
136- /// <param name="filterText">
137- /// The $filter parameter text.
138- /// </param>
139- /// <param name="entitySetName">
140- /// The entity set name.
141- /// </param>
142- /// <typeparam name="T">
143- /// The query type param
144- /// </typeparam>
145- /// <returns>
146- /// The <see cref="ODataQuery{T}"/> query with applied filter parameter.
147- /// </returns>
148- /// <exception cref="ArgumentNullException">
149- /// Argument Null Exception
150- /// </exception>
151- public static ODataQuery < T > Filter < T > ( this ODataQuery < T > query , string filterText , string entitySetName = null )
177+ /// The Filter.
178+ /// </summary>
179+ /// <param name="query">
180+ /// The OData aware query.
181+ /// </param>
182+ /// <param name="filterText">
183+ /// The $filter parameter text.
184+ /// </param>
185+ /// <param name="entitySetName">
186+ /// The entity set name.
187+ /// </param>
188+ /// <typeparam name="T">
189+ /// The query type param
190+ /// </typeparam>
191+ /// <returns>
192+ /// The <see cref="ODataQuery{T}"/> query with applied filter parameter.
193+ /// </returns>
194+ /// <exception cref="ArgumentNullException">
195+ /// Argument Null Exception
196+ /// </exception>
197+ public static ODataQuery < T > Filter < T > ( this ODataQuery < T > query , string filterText , string entitySetName = null )
152198 {
153199 if ( query == null ) throw new ArgumentNullException ( nameof ( query ) ) ;
154200 if ( filterText == null ) throw new ArgumentNullException ( nameof ( filterText ) ) ;
@@ -161,7 +207,7 @@ public static ODataQuery<T> Filter<T>(this ODataQuery<T> query, string filterTex
161207 new Dictionary < string , string > { { "$filter" , filterText } } ) ;
162208
163209 ODataSettings settings = query . ServiceProvider . GetRequiredService < ODataSettings > ( ) ;
164-
210+
165211 FilterClause filterClause = queryOptionParser . ParseFilter ( ) ;
166212 SingleValueNode filterExpression = filterClause . Expression . Accept (
167213 new ParameterAliasNodeTranslator ( queryOptionParser . ParameterAliasNodes ) ) as SingleValueNode ;
@@ -225,7 +271,7 @@ public static ODataQueryOrdered<T> OrderBy<T>(this ODataQuery<T> query, string o
225271 IOrderedQueryable < T > result = ( IOrderedQueryable < T > ) OrderByBinder . OrderApplyToCore ( query , settings . QuerySettings , nodes , edmModel ) ;
226272
227273 return new ODataQueryOrdered < T > ( result , query . ServiceProvider ) ;
228- }
274+ }
229275
230276 private static IEnumerable < T > Enumerate < T > ( IQueryable queryable ) where T : class
231277 {
0 commit comments