WIQL如何在MS SQL中使用LIMIT关键字来查询TFS工作项 [英] How to use LIMIT keyword as using in ms sql by WIQL to query TFS workItem

查看:195
本文介绍了WIQL如何在MS SQL中使用LIMIT关键字来查询TFS工作项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用TFS API,我不知道TFS API是否有LIMIT关键字之类的东西,或者我没有.

I'm working on TFS API, I don't know that TFS API have any things like LIMIT keyword or no.I need it for paging.

谢谢

推荐答案

在TFS WIQL中没有与SQL LIMIT关键字等效的东西,您需要自己实现分页.

There is nothing equivalent to the SQL LIMIT keyword in TFS WIQL, you will need to implement the paging yourself.

一种方法是在第一次访问时检索所有结果,并将其缓存并自行分页.

One approach would be to retrieve all the results on the first access, and cache them and page them yourself.

另一种方法是每次用户页面动态构建WIQL查询.例如:

Another approach would be to dynamically construct the WIQL query each time your user pages. For example:

  1. 运行WIQL查询以仅返回与查询匹配的工作项ID. SELECT [System.Id] FROM WorkItems WHERE <conditions>
  2. 缓存该ID列表
  3. 将该ID列表分成与您的页面大小匹配的组
  4. 每次用户页面时,都按ID显式请求工作项的. SELECT <fields> FROM WorkItems WHERE [System.Id] IN (10,11,12,13,14,15)
  1. Run a WIQL query to return just the work item ID's that match the query. SELECT [System.Id] FROM WorkItems WHERE <conditions>
  2. Cache that list of IDs
  3. Break that list of IDs into groups that match your paging size
  4. Each time your user pages, explicitly request the work item's by ID. SELECT <fields> FROM WorkItems WHERE [System.Id] IN (10,11,12,13,14,15)

根据要实现的目标,您还应该知道TFS工作项跟踪API会在字段值的幕后实现分页/延迟加载,以最大程度地缩短响应时间.您可以通过附加网络嗅探器并在Visual Studio中滚动大型工作项"查询来了解其工作原理.

Depending on what you are trying to achieve, you should also know that the TFS Work Item Tracking API implements paging/lazy loading under the covers for field values, to maximize response times. You can see how this works by attaching a network sniffer and scrolling a large Work Item query in Visual Studio.

有关更多信息,请参见分页字段值:

See Paging of Field Values for more information:

通过选择所有字段,可以最大程度地减少到服务器的往返行程 您的代码将使用的代码.以下代码为 查询和一次往返,每次返回一个标题页面 进入新页面.

You can minimize round trips to the server by selecting all fields that your code will use. The following code makes one round trip for the query and one round trip to return a page of titles every time that a new page is accessed.

WorkItemCollection results = WorkItemStore.Query(
    "SELECT Title FROM Workitems WHERE (ID < 1000)");

foreach (WorkItem item in results)
{
    Console.WriteLine(item.Fields["Title"].Value);
}

如果您的代码访问未在SELECT中指定的字段 子句,则将该字段添加到分页字段集.再来一轮 执行跳闸以刷新该页面以包含该页面的值 字段.

If your code accesses a field that you did not specify in the SELECT clause, that field is added to the set of paged fields. Another round trip is performed to refresh that page to include the values of that field.

这篇关于WIQL如何在MS SQL中使用LIMIT关键字来查询TFS工作项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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