一次调用即可得到多个结果

编程入门 行业动态 更新时间:2024-10-28 11:25:43
本文介绍了一次调用即可得到多个结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在分页数据时,我不仅要返回10个结果,而且还希望获得所有页面中的项目总数.

When paging data, I want to not only return 10 results, but I also want to get the total number of items in all the pages.

如何在一次调用中获得页面的总数和结果?

How can I get the total count AND the results for the page in a single call?

我的分页方法是:

public IList GetByCategoryId(int categoryId,int firstResult,int maxResults) {

public IList GetByCategoryId(int categoryId, int firstResult, int maxResults) {

IList<Article> articles = Session.CreateQuery( "select a from Article as a join a.Categories c where c.ID = :ID") .SetInt32("ID", categoryId) .SetFirstResult(firstResult) .SetMaxResults(maxResults) .List<Article>(); return articles; }

推荐答案

事实是您打了两次电话.但是count(*)调用在大多数数据库中非常便宜,而在主调用之后执行count(*)调用有时会帮助查询缓存.

The truth is that you make two calls. But a count(*) call is very, very cheap in most databases and when you do it after the main call sometimes the query cache helps out.

您的计数器调用通常也会有所不同,它实际上不需要使用内部联接才有意义.还有一些其他小的性能调整,但是大多数时候您不需要它们.

Your counter call will often be a little different too, it doesn't actually need to use the inner joins to make sense. There are a few other little performance tweaks too but most of the time you don't need them.

更多推荐

一次调用即可得到多个结果

本文发布于:2023-10-26 08:12:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1529597.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!