1- using System ;
2- using System . Linq ;
3- using System . Linq . Expressions ;
4-
5- namespace SharpRepository . Repository . Queries
6- {
7- /// <summary>
8- /// Used to define the paging criteria on queries run against a repository.
9- /// </summary>
10- /// <typeparam name="T">The entity type of the repository.</typeparam>
11- /// <typeparam name="TKey">The type of the property that is being sorted.</typeparam>
12- public class PagingOptions < T , TKey > : SortingOptions < T , TKey >
13- {
14- public int PageSize { get ; internal set ; }
15- public int PageNumber { get ; internal set ; }
16- public int Skip { get { return ( PageNumber - 1 ) * PageSize ; } }
17- public int Take { get { return PageSize ; } }
18- public int TotalItems { get ; internal set ; }
19-
20- public PagingOptions ( int pageNumber , int pageSize , Expression < Func < T , TKey > > sortExpression , bool isDescending = false ) : base ( sortExpression , isDescending )
21- {
22- PageSize = pageSize ;
23- PageNumber = pageNumber ;
24- }
25-
26- /// <summary>
27- /// Applies paging to the specified query.
28- /// </summary>
29- /// <param name="query">The query.</param>
30- /// <returns>Paged results.</returns>
31- public override IQueryable < T > Apply ( IQueryable < T > query )
32- {
33- query = base . Apply ( query ) ;
34-
35- TotalItems = query . Count ( ) ;
36-
37- if ( Skip > 0 || Take > 0 )
38- {
39- return query . Skip ( Skip ) . Take ( Take ) ;
40- }
41-
42- return query ;
43- }
44-
45- /// <summary>
46- /// Used in compiling a unique key for a query
47- /// </summary>
48- /// <returns>Unique key for a query</returns>
49- public override string ToString ( )
50- {
51- return String . Format ( "PagingOptions<{0},{1}>\n PageSize: {2}\n PageNumber: {3}\n Sort Expression: {4}\n IsDescending: {5}" ,
52- ( typeof ( T ) ) . Name ,
53- PageSize ,
54- PageNumber ,
55- SortExpression == null ? "null" : SortExpression . ToString ( ) ,
56- IsDescending
57- ) ;
58- }
59- }
60-
61- /// <summary>
62- /// Used to define the paging criteria on queries run against a repository.
63- /// </summary>
64- /// <typeparam name="T">The entity type of the repository.</typeparam>
65- public class PagingOptions < T > : SortingOptions < T >
66- {
67- public int PageSize { get ; internal set ; }
68- public int PageNumber { get ; internal set ; }
69- public int Skip { get { return ( PageNumber - 1 ) * PageSize ; } }
70- public int Take { get { return PageSize ; } }
71- public int TotalItems { get ; set ; }
72-
73- public PagingOptions ( int pageNumber , int pageSize , string sortProperty , bool isDescending = false )
74- : base ( sortProperty , isDescending )
75- {
76- PageSize = pageSize ;
77- PageNumber = pageNumber ;
78- }
79-
80-
81- /// <summary>
82- /// Applies paging to the specified query.
83- /// </summary>
84- /// <param name="query">The query.</param>
85- /// <returns>Paged results.</returns>
86- public override IQueryable < T > Apply ( IQueryable < T > query )
87- {
88- query = base . Apply ( query ) ;
89-
90- TotalItems = query . Count ( ) ;
91-
92- if ( Skip > 0 || Take > 0 )
93- {
94- return query . Skip ( Skip ) . Take ( Take ) ;
95- }
96-
97- return query ;
98- }
99-
100- /// <summary>
101- /// Used in compiling a unique key for a query
102- /// </summary>
103- /// <returns>Unique key for a query</returns>
104- public override string ToString ( )
105- {
106- return String . Format ( "PagingOptions<{0}>\n PageSize: {1}\n PageNumber: {2}\n Sort Property: {3}\n IsDescending: {4}" ,
107- ( typeof ( T ) ) . Name ,
108- PageSize ,
109- PageNumber ,
110- SortProperty ,
111- IsDescending
112- ) ;
113- }
114- }
1+ using System ;
2+ using System . Linq ;
3+ using System . Linq . Expressions ;
4+
5+ namespace SharpRepository . Repository . Queries
6+ {
7+ /// <summary>
8+ /// Used to define the paging criteria on queries run against a repository.
9+ /// </summary>
10+ /// <typeparam name="T">The entity type of the repository.</typeparam>
11+ /// <typeparam name="TSortKey">The type of the property that is being sorted.</typeparam>
12+ public class PagingOptions < T , TSortKey > : SortingOptions < T , TSortKey >
13+ {
14+ public int PageSize { get ; internal set ; }
15+ public int PageNumber { get ; internal set ; }
16+ public int Skip { get { return ( PageNumber - 1 ) * PageSize ; } }
17+ public int Take { get { return PageSize ; } }
18+ public int TotalItems { get ; internal set ; }
19+
20+ public PagingOptions ( int pageNumber , int pageSize , Expression < Func < T , TSortKey > > sortExpression , bool isDescending = false )
21+ : base ( sortExpression , isDescending )
22+ {
23+ PageSize = pageSize ;
24+ PageNumber = pageNumber ;
25+ }
26+
27+ /// <summary>
28+ /// Applies paging to the specified query.
29+ /// </summary>
30+ /// <param name="query">The query.</param>
31+ /// <returns>Paged results.</returns>
32+ public override IQueryable < T > Apply ( IQueryable < T > query )
33+ {
34+ query = base . Apply ( query ) ;
35+
36+ TotalItems = query . Count ( ) ;
37+
38+ if ( Skip > 0 || Take > 0 )
39+ {
40+ return query . Skip ( Skip ) . Take ( Take ) ;
41+ }
42+
43+ return query ;
44+ }
45+
46+ /// <summary>
47+ /// Used in compiling a unique key for a query
48+ /// </summary>
49+ /// <returns>Unique key for a query</returns>
50+ public override string ToString ( )
51+ {
52+ return String . Format ( "PagingOptions<{0},{1}>\n PageSize: {2}\n PageNumber: {3}\n Sort Expression: {4}\n IsDescending: {5}" ,
53+ ( typeof ( T ) ) . Name ,
54+ PageSize ,
55+ PageNumber ,
56+ SortExpression == null ? "null" : SortExpression . ToString ( ) ,
57+ IsDescending
58+ ) ;
59+ }
60+ }
61+
62+ /// <summary>
63+ /// Used to define the paging criteria on queries run against a repository.
64+ /// </summary>
65+ /// <typeparam name="T">The entity type of the repository.</typeparam>
66+ public class PagingOptions < T > : SortingOptions < T >
67+ {
68+ public int PageSize { get ; internal set ; }
69+ public int PageNumber { get ; internal set ; }
70+ public int Skip { get { return ( PageNumber - 1 ) * PageSize ; } }
71+ public int Take { get { return PageSize ; } }
72+ public int TotalItems { get ; set ; }
73+
74+ public PagingOptions ( int pageNumber , int pageSize , string sortProperty , bool isDescending = false )
75+ : base ( sortProperty , isDescending )
76+ {
77+ PageSize = pageSize ;
78+ PageNumber = pageNumber ;
79+ }
80+
81+
82+ /// <summary>
83+ /// Applies paging to the specified query.
84+ /// </summary>
85+ /// <param name="query">The query.</param>
86+ /// <returns>Paged results.</returns>
87+ public override IQueryable < T > Apply ( IQueryable < T > query )
88+ {
89+ query = base . Apply ( query ) ;
90+
91+ TotalItems = query . Count ( ) ;
92+
93+ if ( Skip > 0 || Take > 0 )
94+ {
95+ return query . Skip ( Skip ) . Take ( Take ) ;
96+ }
97+
98+ return query ;
99+ }
100+
101+ /// <summary>
102+ /// Used in compiling a unique key for a query
103+ /// </summary>
104+ /// <returns>Unique key for a query</returns>
105+ public override string ToString ( )
106+ {
107+ return String . Format ( "PagingOptions<{0}>\n PageSize: {1}\n PageNumber: {2}\n Sort Property: {3}\n IsDescending: {4}" ,
108+ ( typeof ( T ) ) . Name ,
109+ PageSize ,
110+ PageNumber ,
111+ SortProperty ,
112+ IsDescending
113+ ) ;
114+ }
115+ }
115116}
0 commit comments