How to get the WorkitemCollection from WorkItemStore using Query(Ids, QueryString) Method

瘦欲@ 提交于 2019-12-08 05:06:37

问题


I have stuck on one problem where I want to get the WorkItemCollection from the WorkItemStore. I know it can be possible by using Query() Method.

But in my scenario Query method is not working as I am using method WorkItemStore.Query Method (Int32[], String). with the String argument as

Select [System.Id],[System.State],[System.Title],[System.WorkItemType] 
from WORKITEMS 
where [System.WorkItemType] = 'Requirement' and [System.TeamProject] = 'Test_Baseline'

But while executing this query It is throwing exception with message as Invalid Query Provided. Can any one tell how do I resolve this problem? Thanks in advanced.


回答1:


@Ankit, The exception I got from running your query using Query(Int32[], String) oveload is:

"The WHERE and ORDER BY clauses of a query string are not supported on a parameterized query."

which I think explains why you cannot run this WIQL using this overload. You should either remove the WHERE clause from the query or use Query(String) method




回答2:


I came here because I am trying to implement a query function that will handle both LIST and TREE queries. In the end I wrote something like this...

    JArray RunQuery(string wiql)
    {
        var i = wiql.ToLower().IndexOf("from workitemlinks");
        if (i > 0)
        {
            // Handle "Tree" queries
            var query = new Query(Store, wiql);
            var linkInfoList = query.RunLinkQuery();
            var parent = linkInfoList.ToDictionary(link => link.TargetId, link => link.SourceId);
            // Remove all WHERE and ORDER BY from query
            var items = tfs.Store.Query(parent.Keys.ToArray(), wiql.Substring(0, i) + "from workitems");
            var result = JsonUtil.ConvertItemList(items);
            foreach (JObject json in result)
            {
                json["Parent"] = parent[json.Value<int>("ID")];
            }
            return result;
        }
        // Handle "List" query
        return JsonUtil.ConvertItemList(Store.Query(wiql));
    }

I hope someone finds this helpful.



来源:https://stackoverflow.com/questions/24524328/how-to-get-the-workitemcollection-from-workitemstore-using-queryids-querystrin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!