Page Select BUG

This commit is contained in:
sunkaixuan 2017-07-08 01:22:14 +08:00
parent cde8d1e6c5
commit 3bc24087c4
4 changed files with 40 additions and 46 deletions

View File

@ -340,6 +340,13 @@ namespace OrmTest.Demo
var s7 = db.Queryable<Student, School>((st, sc) => new object[] { var s7 = db.Queryable<Student, School>((st, sc) => new object[] {
JoinType.Left,st.SchoolId==sc.Id JoinType.Left,st.SchoolId==sc.Id
}).Select((st, sc) => sc).ToList(); }).Select((st, sc) => sc).ToList();
var s8 = db.Queryable<Student, School>((st, sc) => new object[] {
JoinType.Left,st.SchoolId==sc.Id
})
.OrderBy((st, sc) => st.SchoolId)
.Select((st, sc) => sc)
.Take(1).ToList();
} }
private static void Sqlable() private static void Sqlable()
{ {

View File

@ -18,19 +18,19 @@ namespace OrmTest
static void Main(string[] args) static void Main(string[] args)
{ {
// /***Unit Test***/ // /***Unit Test***/
new Select(1).Init(); //new Select(1).Init();
new Field(1).Init(); //new Field(1).Init();
new Where(1).Init(); //new Where(1).Init();
new Method(1).Init(); //new Method(1).Init();
new JoinQuery(1).Init(); //new JoinQuery(1).Init();
new SingleQuery(1).Init(); //new SingleQuery(1).Init();
new SelectQuery(1).Init(); //new SelectQuery(1).Init();
new AutoClose(1).Init(); //new AutoClose(1).Init();
new Insert(1).Init(); //new Insert(1).Init();
new Delete(1).Init(); //new Delete(1).Init();
new Update(1).Init(); //new Update(1).Init();
new Mapping(1).Init(); //new Mapping(1).Init();
new DataTest(1).Init(); //new DataTest(1).Init();
/***Performance Test***/ /***Performance Test***/
new SqlSugarPerformance(100).Select(); new SqlSugarPerformance(100).Select();

View File

@ -124,10 +124,7 @@ namespace SqlSugar
{ {
get get
{ {
return @"WITH PageTable AS( return @"SELECT * FROM ({0}) T WHERE RowIndex BETWEEN {1} AND {2}";
{0}
)
SELECT * FROM (SELECT *,ROW_NUMBER() OVER({1}) AS RowIndex FROM PageTable ) T WHERE RowIndex BETWEEN {2} AND {3}";
} }
} }
public virtual string DefaultOrderByTemplate public virtual string DefaultOrderByTemplate
@ -232,34 +229,25 @@ namespace SqlSugar
} }
} }
sql = new StringBuilder(); sql = new StringBuilder();
sql.AppendFormat(SqlTemplate, GetSelectValue, GetTableNameString, GetWhereValueString, GetGroupByString + HavingInfos, (Skip != null || Take != null) ? null : GetOrderByString); if (this.OrderByValue == null && (Skip != null || Take != null)) this.OrderByValue = " Order By GetDate() ";
if (this.PartitionByValue.IsValuable())
{
this.OrderByValue = this.PartitionByValue + this.OrderByValue;
}
sql.AppendFormat(SqlTemplate, GetSelectValue, GetTableNameString, GetWhereValueString, GetGroupByString + HavingInfos);
sql.Replace("{$:OrderByString:$}", (Skip != null || Take != null) ? string.Format(",ROW_NUMBER() OVER({0}) AS RowIndex ", GetOrderByString) : null);
if (IsCount) { return sql.ToString(); } if (IsCount) { return sql.ToString(); }
if (Skip != null && Take == null) if (Skip != null && Take == null)
{ {
if (this.OrderByValue == null) this.OrderByValue = " Order By GetDate() "; return string.Format(PageTempalte, sql.ToString(), Skip.ObjToInt() + 1, long.MaxValue);
if (this.PartitionByValue.IsValuable())
{
this.OrderByValue = this.PartitionByValue + this.OrderByValue;
}
return string.Format(PageTempalte, sql.ToString(), GetOrderByString, Skip.ObjToInt() + 1, long.MaxValue);
} }
else if (Skip == null && Take != null) else if (Skip == null && Take != null)
{ {
if (this.OrderByValue == null) this.OrderByValue = " Order By GetDate() "; return string.Format(PageTempalte, sql.ToString(), 1, Take.ObjToInt());
if (this.PartitionByValue.IsValuable())
{
this.OrderByValue = this.PartitionByValue + this.OrderByValue;
}
return string.Format(PageTempalte, sql.ToString(), GetOrderByString, 1, Take.ObjToInt());
} }
else if (Skip != null && Take != null) else if (Skip != null && Take != null)
{ {
if (this.OrderByValue == null) this.OrderByValue = " Order By GetDate() "; return string.Format(PageTempalte, sql.ToString(), Skip.ObjToInt() + 1, Skip.ObjToInt() + Take.ObjToInt());
if (this.PartitionByValue.IsValuable())
{
this.OrderByValue = this.PartitionByValue + this.OrderByValue;
}
return string.Format(PageTempalte, sql.ToString(), GetOrderByString, Skip.ObjToInt() + 1, Skip.ObjToInt() + Take.ObjToInt());
} }
else else
{ {
@ -388,7 +376,7 @@ namespace SqlSugar
if (this.TableWithString.IsValuable()) if (this.TableWithString.IsValuable())
{ {
result += "," + string.Join(",", this.EasyJoinInfos.Select(it => string.Format("{0} {1} {2} ",GetTableName(it.Value), it.Key, TableWithString))); result += "," + string.Join(",", this.EasyJoinInfos.Select(it => string.Format("{0} {1} {2} ", GetTableName(it.Value), it.Key, TableWithString)));
} }
else else
{ {
@ -405,19 +393,11 @@ namespace SqlSugar
if (this.OrderByValue == null) return null; if (this.OrderByValue == null) return null;
if (IsCount) return null; if (IsCount) return null;
else else
{
if (!IsSingle() && (Take != null || Skip != null))
{
var result = Regex.Replace(this.OrderByValue, @"\[\w+\]\.", "");
return result;
}
else
{ {
return this.OrderByValue; return this.OrderByValue;
} }
} }
} }
}
public virtual string GetGroupByString public virtual string GetGroupByString
{ {
get get

View File

@ -8,5 +8,12 @@ namespace SqlSugar
{ {
public class SqlServerQueryBuilder: QueryBuilder public class SqlServerQueryBuilder: QueryBuilder
{ {
public override string SqlTemplate
{
get
{
return "SELECT {0}{{$:OrderByString:$}} FROM {1}{2}{3}";
}
}
} }
} }