This commit is contained in:
sunkaixuan 2017-09-27 10:16:51 +08:00
parent 74afe01166
commit cfdcc83bcb

View File

@ -24,6 +24,7 @@ namespace SqlSugar
{
string oldOrderBy = this.OrderByValue;
string externalOrderBy = oldOrderBy;
var isIgnoreOrderBy = this.IsCount && this.PartitionByValue.IsNullOrEmpty();
AppendFilter();
sql = new StringBuilder();
if (this.OrderByValue == null && (Skip != null || Take != null)) this.OrderByValue = " ORDER BY "+ this.Builder.SqlDateNow + " ";
@ -35,10 +36,10 @@ namespace SqlSugar
var rowNumberString = string.Format(",ROW_NUMBER() OVER({0}) AS RowIndex ", GetOrderByString);
string groupByValue = GetGroupByString + HavingInfos;
string orderByValue = (!isRowNumber && this.OrderByValue.IsValuable()) ? GetOrderByString : null;
if (this.IsCount) { orderByValue = null; this.OrderByValue = oldOrderBy; }
if (isIgnoreOrderBy) { orderByValue = null; }
sql.AppendFormat(SqlTemplate, GetSelectValue, GetTableNameString, GetWhereValueString, groupByValue, orderByValue);
sql.Replace(UtilConstants.ReplaceKey, isRowNumber ? (this.IsCount ? null : rowNumberString) : null);
if (this.IsCount) { return sql.ToString(); }
sql.Replace(UtilConstants.ReplaceKey, isRowNumber ? (isIgnoreOrderBy ? null : rowNumberString) : null);
if (isIgnoreOrderBy) { this.OrderByValue = oldOrderBy; return sql.ToString(); }
var result = ToPageSql(sql.ToString(), this.Take, this.Skip);
if (ExternalPageIndex > 0)
{