1

我正在使用 TFS OData 服务来创建工作正常的工作项。现在我需要获取工作项的 ID 并插入数据库以供以后参考,有人可以指导我这个方向吗?

这是我得到的回应。

   <?xml version="1.0" encoding="utf-8" standalone="yes"?>
<entry xml:base="https://tfsodata.visualstudio.com/DefaultCollection/" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" m:etag="W/&quot;datetime'2013-08-31T10%3A23%3A21.1439028%2B00%3A00'&quot;" xmlns="http://www.w3.org/2005/Atom">
  <id>https://tfsodata.visualstudio.com/DefaultCollection/WorkItems(0)</id>
  <title type="text">my test work item</title>
  <summary type="text">test work item created by isuru http://www.google.com</summary>
  <updated>2013-08-31T10:23:21Z</updated>
  <author>
    <name />
  </author>
  <link rel="edit" title="WorkItem" href="WorkItems(0)" />
  <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Attachments" type="application/atom+xml;type=feed" title="Attachments" href="WorkItems(0)/Attachments" />
  <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Links" type="application/atom+xml;type=feed" title="Links" href="WorkItems(0)/Links" />
  <category term="Microsoft.Samples.DPE.ODataTFS.Model.Entities.WorkItem" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
  <content type="application/xml">
    <m:properties>
      <d:Id m:type="Edm.Int32">0</d:Id>
      <d:Project>My Website</d:Project>
      <d:Type>Product Backlog Item</d:Type>
      <d:WebEditorUrl m:null="true" />
      <d:AreaPath m:null="true" />
      <d:IterationPath m:null="true" />
      <d:Revision m:type="Edm.Int32">0</d:Revision>
      <d:Priority m:null="true" />
      <d:Severity m:null="true" />
      <d:StackRank m:type="Edm.Double">0</d:StackRank>
      <d:AssignedTo m:null="true" />
      <d:CreatedDate m:type="Edm.DateTime">2013-08-31T10:23:21.1419032+00:00</d:CreatedDate>
      <d:CreatedBy m:null="true" />
      <d:ChangedDate m:type="Edm.DateTime">2013-08-31T10:23:21.1439028+00:00</d:ChangedDate>
      <d:ChangedBy m:null="true" />
      <d:ResolvedBy m:null="true" />
      <d:Title>my test work item</d:Title>
      <d:State m:null="true" />
      <d:Reason m:null="true" />
      <d:CompletedWork m:type="Edm.Double">0</d:CompletedWork>
      <d:RemainingWork m:type="Edm.Double">0</d:RemainingWork>
      <d:Description>test work item created by isuru http://www.google.com</d:Description>
      <d:ReproSteps m:null="true" />
      <d:FoundInBuild m:null="true" />
      <d:IntegratedInBuild m:null="true" />
      <d:AttachedFileCount m:type="Edm.Int32">0</d:AttachedFileCount>
      <d:HyperLinkCount m:type="Edm.Int32">0</d:HyperLinkCount>
      <d:RelatedLinkCount m:type="Edm.Int32">0</d:RelatedLinkCount>
      <d:Risk m:null="true" />
      <d:StoryPoints m:type="Edm.Double">0</d:StoryPoints>
      <d:OriginalEstimate m:type="Edm.Double">0</d:OriginalEstimate>
      <d:BacklogPriority m:type="Edm.Double">0</d:BacklogPriority>
      <d:BusinessValue m:type="Edm.Int32">0</d:BusinessValue>
      <d:Effort m:type="Edm.Double">0</d:Effort>
      <d:Blocked m:null="true" />
      <d:Size m:type="Edm.Double">0</d:Size>
    </m:properties>
  </content>
</entry>
4

1 回答 1

0

我所做的是将 Guid 添加到您未使用的随机字段中,然后查询该 Guid。

        wi.Title = "New Work Item";
        wi.FoundInBuild = Guid.NewGuid().ToString();
        wi.Type = "Bug";
        wi.Project = "TestProject";

        context.AddToWorkItems(wi);
        context.SaveChanges();
        Debug.WriteLine(String.Format("Work item created"));

        var createdWi = context.WorkItems.Where( d => d.FoundInBuild == wi.FoundInBuild);
于 2014-05-06T11:35:55.290 回答