Sqlerver support distinct use rownumber page

This commit is contained in:
sunkaixuan 2022-03-30 21:23:05 +08:00
parent a6b3c965de
commit 3ab92f8a02

View File

@ -15,8 +15,33 @@ namespace SqlSugar
return "SELECT {0}{"+UtilConstants.ReplaceKey+"} FROM {1}{2}{3}{4}";
}
}
public override string ToSqlString()
{
var oldTake = Take;
var oldSkip = Skip;
var isDistinctPage = IsDistinct && (Take > 1 || Skip > 1);
if (isDistinctPage)
{
Take = null;
Skip = null;
}
var result = _ToSqlString();
if (isDistinctPage)
{
if (this.OrderByValue.HasValue())
{
Take = int.MaxValue;
result = result.Replace("DISTINCT", $" DISTINCT TOP {int.MaxValue} ");
}
Take = oldTake;
Skip = oldSkip;
result =this.Context.SqlQueryable<object>(result).Skip(Skip.Value).Take(Take.Value).ToSql().Key;
public override string ToSqlString()
}
return result;
}
public string _ToSqlString()
{
string oldOrderBy = this.OrderByValue;
string externalOrderBy = oldOrderBy;