WIQL query to get all item under a workitem - tfs

I am looking for a query where i can return all work items and their relation from a area path.
for example : project 1
i need all Featured all Userstories mapped to it all workitem and Bug mapped to userstories,
in short if i took a bug from the object i need somthing like parent id where i can match with the userstory.
string query1 = " SELECT * FROM WorkItemLinks " +
" WHERE ( [System.IterationPath] Under 'iteration1' )" +
" AND ([System.Links.LinkType] = 'System.LinkTypes.Hierarchy-Forward' )" +
" ORDER BY [Microsoft.VSTS.Scheduling.StartDate]";
which throwing an error like below
An exception of type 'Microsoft.TeamFoundation.WorkItemTracking.Client.ValidationException' occurred in Microsoft.TeamFoundation.WorkItemTracking.Client.dll but was not handled in user code
Additional information: TF51005: The query references a field that does not exist. The error is caused by «[System.IterationPath]».
when i checked the dll's are refereed correctly and when i re wrote the query like this the query is working fine
string query = " SELECT * FROM WorkItems"+
" WHERE ( [System.IterationPath] Under 'iteration1' )" +
//" AND ([System.State] = 'Active' OR [System.State] = 'Assessed' ) "+
//" AND ( [Microsoft.VSTS.Scheduling.StartDate] <= '09/13/2017' AND [Microsoft.VSTS.Scheduling.FinishDate] >= '09/13/2017' )"+
" ORDER BY [Microsoft.VSTS.Scheduling.StartDate]";
but this query result does not give the relation ship that if a work item mapped as a child to other i need parent id in the work item object. how to get that. Thanks in advance.

You can try below query:
Install Nuget Package Microsoft.TeamFoundationServer.ExtendedClient for the project.
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
using System;
namespace _0925_WIQL
{
class Program
{
static void Main(string[] args)
{
TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(
new Uri("http://server:8080/tfs/CollectionLC"));
WorkItemStore workItemStore = (WorkItemStore)tpc.GetService(typeof(WorkItemStore));
string query1= " SELECT * FROM WorkItemLinks " +
" WHERE ( Source.[System.IterationPath] Under 'TeamProject\\Iteration 1' )" +
" AND ([System.Links.LinkType] = 'System.LinkTypes.Hierarchy-Forward' )" +
" ORDER BY [Microsoft.VSTS.Scheduling.StartDate]";
Query query = new Query(workItemStore, query1);
WorkItemLinkInfo[] witLinkInfos = query.RunLinkQuery();
foreach (WorkItemLinkInfo witinfo in witLinkInfos)
{
.......
}
Besides, you can also use Wiql Editor. If you want to get all the parent workitems (IDs) from a specific child work item (ID), you can use below WIQL:
SELECT
[System.Id],
[System.WorkItemType],
[System.Title],
[System.AssignedTo],
[System.State]
FROM workitemLinks
WHERE ([System.Links.LinkType] = 'System.LinkTypes.Hierarchy-Forward')
AND ([Target].[System.Id] = 25)
ORDER BY [System.Id]
MODE (Recursive, ReturnMatchingChildren)

Related

Write SQL query to Entity Framework

select *
from [InterViewerComment]
where commentID in (select max(commentID) as commentID
from [InterViewerComment]
where jobID = 45
group by qenID)
This query is correct in SQL, but I want to rewrite it in Entity Framework.
Basically, I want the latest comment for each qenID based on job ID.
Other way to do the same
var query = " select qendidateList.qenName,InterViewerComment.*, candidate_status.status, 0 as ExamMarks, 0 as Skills from [InterViewerComment] " +
" left outer join qendidateList on InterViewerComment.qenID = qendidateList.qenID " +
" left outer join candidate_status on InterViewerComment.candidate_status = candidate_status.Candidate_status " +
" where commentID in( select max(commentID) as commentID from[InterViewerComment] where jobID = 45 group by qenID)";
var CandidateComm_ = db.Database.SqlQuery<interViewerComment>(query).ToList();

FireDAC Query connect to DBGrid

I have FDQuery and DataSource and DBGrid. Now I write this code in Button
FDQuery2->Active = false;
FDQuery2->SQL->Clear();
FDQuery2->SQL->Add(" SELECT C.patient_id, P.patient_name, C.check_id "
" FROM Checkup C "
" INNER JOIN Patient P ON (C.patient_id=P.patient_id) "
" WHERE C.today = " + MaskEdit1->Text +
" ORDER BY C.check_id ");
FDQuery2->Active = true;
and i connect FDQuery to DataSource and tDataSource to DBGrid, but when I click the Button it doesn't show rows. and i am sure that SQL code is work, because when i write inside the SQL String the rows have been shown.
any ideas.
You're missing the ' around your value when concatenating the text. Change your WHERE clause:
FDQuery2->SQL->Clear();
FDQuery2->SQL->Add(" SELECT C.patient_id, P.patient_name, C.check_id "
" FROM Checkup C "
" INNER JOIN Patient P ON (C.patient_id=P.patient_id) "
" WHERE C.today = '" + MaskEdit1->Text + "'" +
" ORDER BY C.check_id ");
You really should learn to use parameterized queries instead, though. It allows the database driver to handle things like properly quoting text or formatting dates for you, and it also (importantly) prevents SQL injection.
FDQuery2->SQL->Clear();
FDQuery2->SQL->Add(" SELECT C.patient_id, P.patient_name, C.check_id "
" FROM Checkup C "
" INNER JOIN Patient P ON (C.patient_id=P.patient_id) "
" WHERE C.today = :today" +
" ORDER BY C.check_id ");
FDQuery2->ParamByName("today")->AsString = MaskEdit1.Text;
FDQuery2->Active = true;

Save just the relationship in neo4j

I am trying to persist just a relationship in Neo4j but doesn't work. See my query. My domain object has this relationship to itself.
#RelatedTo (type="PLUS_ME", direction = Direction.BOTH)
private Set<Errand> plusMe;
Then I run this query with a GraphRepository.
Errand e = new Errand ();
Errand e1 = new Errand ();
e = template.save(e);
e1 = template.save(e1);
p (e.getId() + " " + e1.getId ());
String query = "MATCH (one:Errand)" +
"WHERE one.id = " + e.getId() +
"MATCH (two:Errand)" +
"WHERE two.id = " + e1.getId() +
"CREATE (one)-[b:PLUS_ME]->(two)" +
"CREATE (two)-[a:PLUS_ME]->(one)";
eRepo.query(query, null);
But when I run this query with junit I get 0 as the size that is.
eRepo.findByPlusMe(e).size();
use parameters
you don't need the inverse relationship
are you sure your match statements returns the correct errands?
can you show the structure of your Errand class?
is your findByPlusMe repository query a annotated or derived query?

Invalid column name error

I am trying to sort by transient property but fails with SQL Error: Invalid column name error .
Pls find below my code :
In domain class declared :
static transients = ['sortCandidateLastName']
Query which I am trying to execute:
When I am trying to run the below query in Oracle :It runs fine
( select * from ( select row_.* ,rownum rownum_ from ( select * from booking b where b.marked_deleted='N' order by (select c.cand_id from candidate c where b.cand_id = c.cand_id) asc ) row_ where rownum <= 15 ) where rownum > 0)
GSP code:
<g:sortableColumn property="sortCandidateLastName" title="Sort By Candidate Last Name" />
But when Hibernate is trying to read it ,it throws Invalid column name : ResultSet.getInt(clazz_)
Transient properties are not persisted so it's impossible to write a query which sorts by a transient property. If you retrieve a list of objects from a query and want to sort them by a transient property, you'll have to do it in Groovy code, e.g.
// an example domain class with a transient property
class Book {
private static Long SEQUENCE_GENERATOR = 0
String isbn
String title
Long sequence = ++SEQUENCE_GENERATOR
static transients = ['sequence']
}
// get a list of books from the DB and sort by the transient property
def books = Book.list()
books.sort { it.sequence }
You cant sort on transient field. There is no actual database column for a transient field! So your sql would always throw an error!
I tried using jdbcTemplate and gives me the required functionality.
Code snippet:
GSP Layer:
<g:sortable property="sortCandidateLastName">
<g:message code="booking.alphabetical.label" default="Alphabetical(A-Z)" />
</g:sortable>
Domain layer:
just defined a transient property :
static transients = ['sortCandidateLastName']
Reason for adding the transient field : SO that it doesn't throw me any exception like missing property.
Controller layer :
if(params.sort == "sortCandidateLastName" )
{
bookingCandList= bookingService.orderByCandidateLastName(params.max, params.order,params.offset.toInteger())//Booking.getSortCandidateLastName(params.max, params.order,params.offset.toInteger()) //
}
Service layer :
def jdbcTemplate
public List orderByCandidateLastName(Integer max, String sortOrder,Integer offset) {
println "Inside the getcandidateLastName ${max} :: offset ${offset}"
def sortedList
int minRow = offset
int maxRow = offset+max
String queryStr = " select * from " +
" ( "+
" select row_.* " +
" ,rownum rownum_ " +
" from " +
" ( " +
" select * from booking b where b.item_id= 426 and b.marked_deleted='N' order by " +
" (select c.cand_id from candidate c where b.cand_id = c.cand_id) ${sortOrder} "+
" ) row_ "+
"where rownum <= ${maxRow} " +
") " +
"where rownum > ${minRow}"
return jdbcTemplate.queryForList(queryStr)
}
Configuration of JDBC template :
// Place your Spring DSL code here
import org.springframework.jdbc.core.JdbcTemplate
beans = {
..........
jdbcTemplate(JdbcTemplate) {
dataSource = ref('dataSource')
}
}
Hope it helps to ..
Cheers

How to retrieve TFS2010 projects from specific collection

I'm looking around for a good example to work with TFS 2010 collections,projects, and workitems to start with.
I am able to iterate through collections and Projects using the following code (thanks to original coder)
Dim tfsServer As String = "http://test.domain.com:8080/tfs"
tfsServer = tfsServer.Trim()
Dim tfsUri As Uri
tfsUri = New Uri(tfsServer)
Dim configurationServer As New TfsConfigurationServer(tfsUri)
configurationServer = TfsConfigurationServerFactory.GetConfigurationServer(tfsUri)
' Get the catalog of team project collections
Dim collectionNodes As ReadOnlyCollection(Of CatalogNode)
Dim gVar As Guid() = New Guid() {CatalogResourceTypes.ProjectCollection}
collectionNodes = configurationServer.CatalogNode.QueryChildren(gVar, False, CatalogQueryOptions.None)
Dim strName As New StringBuilder
Dim strCollection As New StringBuilder
For Each collectionNode In collectionNodes
Dim collectionId As Guid = New Guid(collectionNode.Resource.Properties("InstanceID"))
strName.Length = 0
Dim teamProjectCollection As New TfsTeamProjectCollection(tfsUri)
teamProjectCollection = configurationServer.GetTeamProjectCollection(collectionId)
Response.Write("Collection:" & teamProjectCollection.Name & "<br/>")
' Get a catalog of team projects for the collection
Dim hVar As Guid() = New Guid() {CatalogResourceTypes.TeamProject}
Dim projectNodes As ReadOnlyCollection(Of CatalogNode)
projectNodes = collectionNode.QueryChildren(hVar, False, CatalogQueryOptions.None)
' List the team projects in the collection
For Each projectNode In projectNodes
strName.AppendLine(projectNode.Resource.DisplayName & "<br>")
'System.Console.WriteLine(" Team Project: " + projectNode.Resource.DisplayName)
Next
Response.Write(strName.ToString())
Next
I want to read specific project from a collection and iterate through workitems (tasks,bugs,issues,etc). Any help would be highly appreciated.
Thanks.
You can run any query you like in the teamProjectCollection - level with:
WorkItemStore workItemStore = (WorkItemStore)teamProjectCollection.GetService(typeof(WorkItemStore));
WorkItemCollection queryResults = workItemStore.Query(query);
foreach (WorkItem workitem in queryResults)
{
Console.WriteLine(workitem.Title);
}
Now you only have to formulate the query - string in something that provides you with what you need.
Queries are WIQL - like. This very basic can give you all work items within a TeamProject:
SELECT [System.Id], [System.WorkItemType], [System.Title], [System.AssignedTo], [System.State] FROM WorkItems WHERE [System.TeamProject] = #project
#project is in our case here the projectNode.Resource.DisplayName
(You can save any query you 've graphically set in TFS with 'Save as' as a *.wiq file & then use it's content programmatically)

Resources