9

I've got the following WIQL query for a TFS project:

string query = "SELECT * FROM Issue WHERE [System.TeamProject] = @Project "+
                "AND [Assigned To] IN (@AssignedTo)";

Dictionary<string, object> parameters = new Dictionary<string, object>();
parameters.Add("Project","test");
parameters.Add("AssignedTo","'chris','tfsuser'");
WorkItemStore.Query(query, parameters);

This is being run via the .NET TFS API.

My problem is with the AssignedTo parameter. How is this meant to be specified? I've tried it as a string[], List<string> as well as with and without quotes as above. Each one doesn't seem to work.

Chris S
  • 64,770
  • 52
  • 221
  • 239
  • I just spent a few minutes looking at this. I hope you get the answer, because I could definitely foresee running into this. Worse comes to worse, you could just do string manipulation on your own and replace the @AssignedTo with the list of values of your choice. – Robaticus Feb 14 '11 at 15:03
  • http://stackoverflow.com/questions/14282712/how-to-use-limit-keyword-as-using-in-ms-sql-by-wiql-to-query-tfs-workitem Could you help me? – knowwebapp.com Jan 11 '13 at 17:14

2 Answers2

10

I understand what you're trying to do, but it doesn't look like it's possible. The query that you want is this:

WHERE [System.AssignedTo] in ('John Smith', 'Jane Citizen')

Which is semantically the same as this:

WHERE [System.AssignedTo] = 'John Smith' OR [System.AssignedTo] = 'Jane Citizen'

The only way I can work out how to achieve it in code is by specifying the identities as separate parameters:

TfsTeamProjectCollection tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("http://localhost:8080/tfs/"));
WorkItemStore wis = tfs.GetService<WorkItemStore>();

Dictionary<string, string> values = new Dictionary<string, string>();

values.Add("parameter1", "John Smith");
values.Add("parameter2", "Jane Citizen");

Query query = new Query(wis, "SELECT [System.Id] FROM WorkItems WHERE [System.AssignedTo] IN (@parameter1, @parameter2)", values);

WorkItemCollection workItems = wis.Query(query.QueryString);
WorkItem workItem = workItems[0];
granth
  • 8,919
  • 1
  • 43
  • 60
2

Assigned To field is actually [System.AssignedTo]. I don't believe using the display name of the field will work.

Ryan Cromwell
  • 2,613
  • 1
  • 17
  • 33
  • 1
    I have tried both and neither work unfortunately. I think I'm going to have scrap the parameters and do some string concat – Chris S Feb 17 '11 at 23:30