Merge branch 'master' of github.com:dotnetcore/FreeSql

This commit is contained in:
luoyunchong 2021-09-16 00:21:28 +08:00
commit f6c8f171e6
2 changed files with 8 additions and 4 deletions

View File

@ -41,7 +41,8 @@ namespace FreeSql.Odbc.SqlServer
//if (_limit > 0) sb.Append("TOP ").Append(_skip + _limit).Append(" "); //TOP 会引发 __rownum__ 无序的问题 //if (_limit > 0) sb.Append("TOP ").Append(_skip + _limit).Append(" "); //TOP 会引发 __rownum__ 无序的问题
if (_skip <= 0 && _limit > 0) sb.Append("TOP ").Append(_limit).Append(" "); if (_skip <= 0 && _limit > 0) sb.Append("TOP ").Append(_limit).Append(" ");
sb.Append(field); sb.Append(field);
if (_skip > 0)
if (_limit > 0)
{ {
if (string.IsNullOrEmpty(_orderby)) if (string.IsNullOrEmpty(_orderby))
{ {
@ -49,6 +50,7 @@ namespace FreeSql.Odbc.SqlServer
if (pktb != null) _orderby = string.Concat(" \r\nORDER BY ", pktb.Alias, ".", _commonUtils.QuoteSqlName(pktb?.Table.Primarys.First().Attribute.Name)); 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)); else _orderby = string.Concat(" \r\nORDER BY ", _tables.First().Alias, ".", _commonUtils.QuoteSqlName(_tables.First().Table.Columns.First().Value.Attribute.Name));
} }
if (_skip > 0) // 注意这个判断,大于 0 才使用 ROW_NUMBER ,否则属于第一页直接使用 TOP
sb.Append(", ROW_NUMBER() OVER(").Append(_orderby).Append(") AS __rownum__"); sb.Append(", ROW_NUMBER() OVER(").Append(_orderby).Append(") AS __rownum__");
} }
sb.Append(" \r\nFROM "); sb.Append(" \r\nFROM ");

View File

@ -41,7 +41,8 @@ namespace FreeSql.SqlServer.Curd
//if (_limit > 0) sb.Append("TOP ").Append(_skip + _limit).Append(" "); //TOP 会引发 __rownum__ 无序的问题 //if (_limit > 0) sb.Append("TOP ").Append(_skip + _limit).Append(" "); //TOP 会引发 __rownum__ 无序的问题
if (_skip <= 0 && _limit > 0) sb.Append("TOP ").Append(_limit).Append(" "); if (_skip <= 0 && _limit > 0) sb.Append("TOP ").Append(_limit).Append(" ");
sb.Append(field); sb.Append(field);
if (_skip > 0)
if (_limit > 0)
{ {
if (string.IsNullOrEmpty(_orderby)) if (string.IsNullOrEmpty(_orderby))
{ {
@ -49,6 +50,7 @@ namespace FreeSql.SqlServer.Curd
if (pktb != null) _orderby = string.Concat(" \r\nORDER BY ", pktb.Alias, ".", _commonUtils.QuoteSqlName(pktb?.Table.Primarys.First().Attribute.Name)); 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)); else _orderby = string.Concat(" \r\nORDER BY ", _tables.First().Alias, ".", _commonUtils.QuoteSqlName(_tables.First().Table.Columns.First().Value.Attribute.Name));
} }
if (_skip > 0) // 注意这个判断,大于 0 才使用 ROW_NUMBER ,否则属于第一页直接使用 TOP
sb.Append(", ROW_NUMBER() OVER(").Append(_orderby).Append(") AS __rownum__"); sb.Append(", ROW_NUMBER() OVER(").Append(_orderby).Append(") AS __rownum__");
} }
sb.Append(" \r\nFROM "); sb.Append(" \r\nFROM ");