File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed
Src/Asp.NetCore2/SqlSugar/Realization Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,32 @@ public override string SqlTemplate
2121 }
2222 }
2323 public override string ToSqlString ( )
24+ {
25+ var oldTake = Take ;
26+ var oldSkip = Skip ;
27+ var isDistinctPage = IsDistinct && ( Take > 1 || Skip > 1 ) ;
28+ if ( isDistinctPage )
29+ {
30+ Take = null ;
31+ Skip = null ;
32+ }
33+ var result = _ToSqlString ( ) ;
34+ if ( isDistinctPage )
35+ {
36+ if ( this . OrderByValue . HasValue ( ) )
37+ {
38+ Take = int . MaxValue ;
39+ result = result . Replace ( "DISTINCT" , $ " DISTINCT TOP { int . MaxValue } ") ;
40+ }
41+ Take = oldTake ;
42+ Skip = oldSkip ;
43+ result = this . Context . SqlQueryable < object > ( result ) . Skip ( Skip ?? 0 ) . Take ( Take ?? 0 ) . ToSql ( ) . Key ;
44+
45+
46+ }
47+ return result ;
48+ }
49+ public string _ToSqlString ( )
2450 {
2551 string oldOrderBy = this . OrderByValue ;
2652 string externalOrderBy = oldOrderBy ;
Original file line number Diff line number Diff line change @@ -35,7 +35,7 @@ public override string ToSqlString()
3535 }
3636 Take = oldTake ;
3737 Skip = oldSkip ;
38- result = this . Context . SqlQueryable < object > ( result ) . Skip ( Skip . Value ) . Take ( Take . Value ) . ToSql ( ) . Key ;
38+ result = this . Context . SqlQueryable < object > ( result ) . Skip ( Skip ?? 0 ) . Take ( Take ?? 0 ) . ToSql ( ) . Key ;
3939
4040
4141 }
You can’t perform that action at this time.
0 commit comments