TFS Api - Query error with Datetime

Asked

Viewed 83 times

4

I am trying to perform a query using the TFS API where I need to get all the Workitems that have been edited from a certain date, however I get the following error:

An unhandled Exception of type 'Microsoft.TeamFoundation.Workitemtracking.Client.Validationexception' occurred in Microsoft.TeamFoundation.Workitemtracking.Client.dll

Additional information: You cannot Supply a time with the date when running a query using date Precision. The error is caused by «[Changed Date] > '09/11/2015 14:12:43'».

I need to query using the date and time, but I think that’s what’s causing the error, below the code I’m using for the query:

var query = "SELECT [ID] FROM WorkItem WHERE [Work Item Type] = '{0}' AND [Changed Date] > '{1}'";
var workItens = GetWorkItemStory().Query(string.Format(query, WORKITEM_TYPE, dataBase));
return (from WorkItem workItem in workItens select workItem).ToList();

Any idea what I can do to solve the problem?

1 answer

2


I solved using a "POG" with Linq.

When I get the Api items I search all with the same date or higher than I want, without considering the time, then I do a Search only from the time I want. It’s not something beautiful but it’s functional.

var query = "SELECT [ID] FROM WorkItem WHERE [Work Item Type] = '{0}' AND [Changed Date] >= '{1}'";
var workItens = GetWorkItemStory().Query(string.Format(query, WORKITEM_TYPE, dataBase.ToShortDateString()));
return (from WorkItem workItem in workItens where workItem.ChangedDate > dataBase select workItem).ToList();

But if someone can explain to me the reason and a more "beautiful" solution I will accept as an answer.

  • 1

    It’s not POG. It’s the right way. + 1.

  • @pedrocamarajunior o It helps a lot, leaves the code leaner!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.