diff --git a/Src/Asp.Net/SqlServerTest/Demos/1_Query.cs b/Src/Asp.Net/SqlServerTest/Demos/1_Query.cs index 213705614..ab56c0a3a 100644 --- a/Src/Asp.Net/SqlServerTest/Demos/1_Query.cs +++ b/Src/Asp.Net/SqlServerTest/Demos/1_Query.cs @@ -132,7 +132,7 @@ namespace OrmTest.Demo int count = 0; var list4 = db.Queryable() - .PartitionBy(it => new { it.Name }).Take(1).ToPageList(2,3,ref count); + .PartitionBy(it => new { it.Name }).Take(1).ToPageList(3,3,ref count); //SqlFunc.AggregateSum(object thisValue) //SqlFunc.AggregateAvg(TResult thisValue) diff --git a/Src/Asp.Net/SqlServerTest/Program.cs b/Src/Asp.Net/SqlServerTest/Program.cs index 8756af173..684248239 100644 --- a/Src/Asp.Net/SqlServerTest/Program.cs +++ b/Src/Asp.Net/SqlServerTest/Program.cs @@ -37,14 +37,14 @@ namespace OrmTest /***Demo***/ OrmTest.Demo.Query.Init(); - OrmTest.Demo.Insert.Init(); - OrmTest.Demo.Delete.Init(); - OrmTest.Demo.Update.Init(); - OrmTest.Demo.DbFirst.Init(); - OrmTest.Demo.JoinSql.Init(); - OrmTest.Demo.Filter.Init(); - OrmTest.Demo.ComplexModel.Init(); - OrmTest.Demo.CodeFirst.Init(); + //OrmTest.Demo.Insert.Init(); + //OrmTest.Demo.Delete.Init(); + //OrmTest.Demo.Update.Init(); + //OrmTest.Demo.DbFirst.Init(); + //OrmTest.Demo.JoinSql.Init(); + //OrmTest.Demo.Filter.Init(); + //OrmTest.Demo.ComplexModel.Init(); + //OrmTest.Demo.CodeFirst.Init(); } } } diff --git a/Src/Asp.Net/SqlSugar/Abstract/SqlBuilderProvider/QueryBuilder.cs b/Src/Asp.Net/SqlSugar/Abstract/SqlBuilderProvider/QueryBuilder.cs index 553e3eba8..d3e933bb9 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/SqlBuilderProvider/QueryBuilder.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/SqlBuilderProvider/QueryBuilder.cs @@ -223,7 +223,7 @@ namespace SqlSugar } public virtual string ToSqlString() { - string oldOrderBy=this.OrderByValue; + string oldOrderBy = this.OrderByValue; if (!IsDisabledGobalFilter && this.Context.QueryFilter.GeFilterList.IsValuable()) { var gobalFilterList = this.Context.QueryFilter.GeFilterList.Where(it => it.FilterName.IsNullOrEmpty()).ToList(); @@ -249,23 +249,25 @@ namespace SqlSugar sql.AppendFormat(SqlTemplate, GetSelectValue, GetTableNameString, GetWhereValueString, GetGroupByString + HavingInfos, (!isRowNumber && this.OrderByValue.IsValuable()) ? GetOrderByString : null); sql.Replace("{$:OrderByString:$}", isRowNumber ? (this.IsCount ? null : rowNumberString) : null); if (IsCount) { return sql.ToString(); } - var result= ToPageSql(sql.ToString(),this.Take,this.Skip); - if (ExternalPageIndex > 0) { + var result = ToPageSql(sql.ToString(), this.Take, this.Skip); + if (ExternalPageIndex > 0) + { result = string.Format("SELECT *,ROW_NUMBER() OVER(ORDER BY GETDATE()) AS RowIndex2 FROM ({0}) ExternalTable ", result); - result = ToPageSql(result, (ExternalPageIndex-1)*ExternalPageSize,ExternalPageSize,true); + result = ToPageSql2(result,ExternalPageIndex, ExternalPageSize, true); } this.OrderByValue = oldOrderBy; return result; } - public virtual string ToCountSql(string sql) { + public virtual string ToCountSql(string sql) + { - return string.Format(" SELECT COUNT(1) FROM ({0}) CountTable ",sql); + return string.Format(" SELECT COUNT(1) FROM ({0}) CountTable ", sql); } - - public virtual string ToPageSql(string sql,int? take,int? skip,bool isExternal=false) + + public virtual string ToPageSql(string sql, int? take, int? skip, bool isExternal = false) { - string temp = isExternal?ExternalPageTempalte:PageTempalte; + string temp = isExternal ? ExternalPageTempalte : PageTempalte; if (skip != null && take == null) { return string.Format(temp, sql.ToString(), skip.ObjToInt() + 1, long.MaxValue); @@ -283,7 +285,13 @@ namespace SqlSugar return sql.ToString(); } } - + + public virtual string ToPageSql2(string sql, int? pageIndex, int? pageSize, bool isExternal = false) + { + string temp = isExternal ? ExternalPageTempalte : PageTempalte; + return string.Format(temp, sql.ToString(), (pageIndex - 1) * pageSize+1, pageIndex * pageSize); + } + public virtual string ToJoinString(JoinQueryInfo joinInfo) { return string.Format(