确定 SPQuery 返回的项目总数 [英] Determine Total Count Of Items Returned By SPQuery

查看:51
本文介绍了确定 SPQuery 返回的项目总数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在对 SharePoint 2010 中的一个大型列表运行多个 CAML 查询,并将结果以网格视图的形式显示给最终用户.我希望翻阅查询返回的结果以提高性能.但是,我需要在分页控件上显示查询返回的项目总数.我的问题是,如何确定每个查询将返回的项目总数,而无需在单个 SPListItemCollection 中实际返回所有项目?准确地说,我希望一次翻阅结果 10 项;我怎样才能做到这一点并且仍然拥有查询返回的所有项目的总数?

I'm running a number of CAML queries against a large list in SharePoint 2010, and displaying the results in a gridview to the end user. I wish to page through the results returned by the query to improve performance. However, I am required to display a total count of the items returned by the query on the paging control. My question is, how can I determine the total number of items that will be returned by each query without actually returning them all in a single SPListItemCollection? To be precise, I wish to page through the results 10 items at a time; how can I do this and still have a total count of all items returned by the query?

更新

到目前为止,给出的答案都没有解决我的问题 - 因此,我提供了悬赏.我需要能够获得 CAML 查询将返回的项目总数,而不必运行查询并返回所有项目.这将使我能够向最终用户显示此总计数值(设定要求),同时分页浏览项目集合以在 gridview 中显示特定页面的结果.这将避免对包含 gridview 首次加载的页面上的大型列表造成巨大的性能影响.

So far, none of the answers given have addressed my question - as such, I'm offering a bounty. I need to be able to get a total count of the number of items that a CAML query will return without having to run the query and return all of the items. This will enable me to display this total count value to the end user (a set requirement), while paging through the items collection to display a specific page of results in a gridview. This would avoid a massive performance hit for large lists on the page containing the gridview first loading.

如果没有人对上述问题提供有效答案,我将接受提供指向 MSDN 文章链接的答案,该文章明确指出无法实现上述功能.

If no one offers a valid answer to the above, I will accept an answer that gives a link to an MSDN article that explicitly says that the above functionality cannot be implemented.

谢谢,MagicAndi.

Thanks, MagicAndi.

推荐答案

不幸的是,我认为您不会从 MSDN 得到明确的答案,说明什么不可能.. 只有是什么.这是整个 msdn 上的 CAML 查询架构页面.那里没有提到任何类型的计数"函数.

Unfortunately, I don't think you're going to get a definitive answer from MSDN saying what isn't possible... only what is. Here is the entire CAML Query Schema page on msdn. There is no mention of any type of "count" function there.

至于解决您的问题,首先您需要选择正确的查找项目的方法.例如,这里有几个案例:

As for solving your problem, first you need to choose the correct method for finding items. For example, here are a couple cases:

  1. 来自一个列表的项目?CAML
  2. 来自同一站点的几个列表中的项目?SPSiteDataQuery
  3. 来自多个站点的多个列表的项目?搜索 API

其次,您可以在 Web 部件中实现某种缓存,以减少排序/页面/过滤所需的时间.我喜欢使用 System.Web.HttpRuntime.Cache 来存储 DataTable(这样可以轻松更改检索项目的方法,同时您的网格可以继续使用数据表).您也可以使用 Page.Session 而不是缓存.

Second, you can implement some sort of caching in your web part to reduce the time it takes to sort/page/filter. I like using the System.Web.HttpRuntime.Cache to store a DataTable (makes it easy to change the method for retrieving items while your grid can keep using the datatable). You could also use Page.Session instead of caching.

这篇关于确定 SPQuery 返回的项目总数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆