gpt4 book ai didi

c# - WIQL 查询不包括 "System.AssignedTo"字段

转载 作者:太空宇宙 更新时间:2023-11-03 23:04:17 25 4
gpt4 key购买 nike

我有这个 WIQL,它的目的是找到分配给工作项的用户。

var wiql = string.Format("SELECT [System.Id], [System.WorkItemType], [System.Title], [System.AssignedTo], [System.State]" +
" FROM WorkItems" +
" WHERE ([System.TeamProject] = '{0}')" +
" AND ([System.WorkItemType] = 'Task' OR [System.WorkItemType] = 'Bug')" +
" ORDER BY [System.Id]", projectName);

我正在执行它......

Wiql wiql = new Wiql() { Query = wiqlQueryString };

using (var workItemTrackingHttpClient = new WorkItemTrackingHttpClient(VstsAccess.AccessUri, VstsAccess.AccessCredentials))
{
var workItemQueryResult = workItemTrackingHttpClient.QueryByWiqlAsync(wiql).Result;

if (workItemQueryResult != null && workItemQueryResult.WorkItemRelations.Any())
{
List<int> sourceIdList = new List<int>();
foreach (var item in workItemQueryResult.WorkItemRelations)
sourceIdList.Add(item.Target.Id);

int[] arr = sourceIdList.ToArray();
string[] fields = { "System.Id", "System.WorkItemType", "System.AssignedTo", "System.Title", "System.Description", "System.State", "System.IterationPath", "System.TeamProject", "System.ChangedDate", "System.ChangedBy", "System.CreatedDate" };
return workItemTrackingHttpClient.GetWorkItemsAsync(arr, fields, workItemQueryResult.AsOf).Result;
}
else
return new List<WorkItem>();
}

但是“AssignedTo”和“Description”字段没有出现在工作项的字典字段集中。为什么会这样,我该如何解决?

最佳答案

查询结果将只包含非空字段,即没有人分配给工作项,该字段根本不会在 Fields 字典中。

您需要对这些字段实现自定义检查,并根据您的逻辑将它们分配给某些东西:

            int[] arr = ids.ToArray();

string[] fields = new string[] {
"System.Id",
"System.Title",
"System.State",
"System.AssignedTo"
};

var workItems = await workItemTrackingHttpClient.GetWorkItemsAsync(arr, fields, workItemQueryResult.AsOf);

List<WorkItemData> list = new List<WorkItemData>();

foreach (var workItem in workItems)
{
var wi = new WorkItemData(workItem.Id.Value);

wi.Title = workItem.Fields["System.Title"].ToString();
wi.State = workItem.Fields["System.State"].ToString();
wi.AssignedTo = workItem.Fields.ContainsKey("System.AssignedTo") ? workItem.Fields["System.AssignedTo"].ToString() : "";

list.Add(wi);

}

关于c# - WIQL 查询不包括 "System.AssignedTo"字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41882996/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com