修复: _limit作为判断依据

使用_limit作为判断依据
This commit is contained in:
CLKCLK 2021-09-14 12:04:23 +08:00
parent 9c4ea7ef89
commit 5ed9888fa1

View File

@ -42,14 +42,15 @@ namespace FreeSql.Odbc.SqlServer
if (_skip <= 0 && _limit > 0) sb.Append("TOP ").Append(_limit).Append(" ");
sb.Append(field);
if (_limit > 0)
{
if (string.IsNullOrEmpty(_orderby))
{
var pktb = _tables.Where(a => a.Table.Primarys.Any()).FirstOrDefault();
if (pktb != null) _orderby = string.Concat(" \r\nORDER BY ", pktb.Alias, ".", _commonUtils.QuoteSqlName(pktb?.Table.Primarys.First().Attribute.Name));
else _orderby = string.Concat(" \r\nORDER BY ", _tables.First().Alias, ".", _commonUtils.QuoteSqlName(_tables.First().Table.Columns.First().Value.Attribute.Name));
}
if (_skip > 0)
{
if (_skip > 0) // 注意这个判断,大于 0 才使用 ROW_NUMBER ,否则属于第一页直接使用 TOP
sb.Append(", ROW_NUMBER() OVER(").Append(_orderby).Append(") AS __rownum__");
}
sb.Append(" \r\nFROM ");