Update Group By

This commit is contained in:
sunkaixuan 2025-03-10 12:19:03 +08:00
parent b0d995a6b3
commit c292512649
2 changed files with 6 additions and 4 deletions

View File

@ -928,6 +928,7 @@ namespace SqlSugar
if (selectSql.Contains(this.GroupBySql))
{
result = selectSql;
this.GroupByIsReplace = true;
}
}
this.SelectCacheKey = result;
@ -1096,6 +1097,7 @@ namespace SqlSugar
#region NoCopy
internal bool GroupByIsReplace { get; set; }
internal List<QueryableFormat> QueryableFormats { get; set; }
internal bool IsClone { get; set; }
public bool NoCheckInclude { get; set; }

View File

@ -69,10 +69,6 @@ namespace SqlSugar
if (isFirst && oldOrderByValue == "ORDER BY GETDATE() ") { this.OrderByValue = null; }
var rowNumberString = string.Format(",ROW_NUMBER() OVER({0}) AS RowIndex ", GetOrderByString);
string groupByValue = GetGroupByString + HavingInfos;
if (this.GroupParameters?.Any()==true)
{
groupByValue = groupByValue.Replace(this.GroupBySqlOld,this.GroupBySql);
}
string orderByValue = (!isRowNumber && this.OrderByValue.HasValue()) ? GetOrderByString : null;
if (isIgnoreOrderBy) { orderByValue = null; }
sql.AppendFormat(SqlTemplate, GetSelect(isFirst,isTop), base.GetTableNameString, base.GetWhereValueString, groupByValue, orderByValue);
@ -112,6 +108,10 @@ namespace SqlSugar
{
result = result.Replace("TOP 1 DISTINCT", "TOP 1 ");
}
if (this.GroupParameters?.Any() == true&&this.GroupByIsReplace)
{
result = result.Replace(this.GroupBySqlOld, this.GroupBySql);
}
return result;
}