-
Notifications
You must be signed in to change notification settings - Fork 859
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
3.2.5 查询后自动添加了orderby #1126
Comments
明白了。。。没有指定排序字段 会自动把主键加到排序里面 |
如果默认没有排序,并且表没有聚合索引 ,分页数据会乱。 |
.OrderBy(g => g.key.TM) 加这行就行了,不加分页出来的数据也会有顺序问题。 |
@2881099 已经发现了 感谢 |
@2881099 只不过在第一页的时候他不会提示错误 到第二页的时候才会报出错误 就忽略了 |
2881099
added a commit
that referenced
this issue
May 27, 2022
因为第一页直接 TOP 查询,第二页才走的分页 代码是这样写的: if (_skip > 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));
}
sb.Append(_orderby).Append($" \r\nOFFSET {_skip} ROW");
if (_limit > 0) sb.Append($" \r\nFETCH NEXT {_limit} ROW ONLY");
} |
你可以观察监听一下 SQL,我们所有第一页都是 TOP 10,而不需要 row_number() 或者 offset row fetch next |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
问题描述及重现步骤:
数据库的具体版本
安装的包
.net framework/. net core? 及具体版本
求助!
The text was updated successfully, but these errors were encountered: