Browse Source

-

pull/12/MERGE
sunkaixuan 7 years ago
parent
commit
f1428ff1ff
  1. 2
      Src/Asp.Net/SqlServerTest/Demos/1_Query.cs
  2. 16
      Src/Asp.Net/SqlServerTest/Program.cs
  3. 24
      Src/Asp.Net/SqlSugar/Abstract/SqlBuilderProvider/QueryBuilder.cs

2
Src/Asp.Net/SqlServerTest/Demos/1_Query.cs

@ -132,7 +132,7 @@ namespace OrmTest.Demo
int count = 0;
var list4 = db.Queryable<Student>()
.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>(TResult thisValue)

16
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();
}
}
}

24
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);
@ -284,6 +286,12 @@ namespace SqlSugar
}
}
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(

Loading…
Cancel
Save