2012-02-23 39 views

回答

3

你並不需要使用RetryPolicy了點。有兩個選項:

使用.AsTableServiceQuery()上查詢。這會將您的查詢轉換爲一個CloudTableQuery對象,該對象本身處理連續令牌。這是最簡單的路線。例如:

var query = (from r in Rows 
      where r.PartitionKey == "whatever" 
      select r).AsTableServiceQuery(); 

否則,您可以使用開始/ EndExecuteSegmented()和處理自己的標記。上CloudTableQuery <

澄清>

有傾斜的參考CloudTableQuery <>的上Scott Densmore's blog行爲。但我也把以下相當混亂的代碼扔在一起來證明它。測試通過,它確實使用連續令牌來檢索所有插入的實體。如果你使用HTTP,你可以用Fiddler看它,並看到令牌來回。

 [Test, Explicit] 
     public void WriteAndReadALotOfRows() 
     { 
      CloudStorageAccount acct = CloudStorageAccount.Parse("PUT IN SOME CREDS HERE"); 
      TableServiceContext ctx = null; 
      List<TestEntity> testEntities = new List<TestEntity>(2000); 

      acct.CreateCloudTableClient().CreateTableIfNotExist("Test"); 

      //Create entities 
      for (int i = 0; i < 2000; i++) 
      { 
       if (i % 100 == 0) 
       { 
        if (ctx != null) 
        { 
         ctx.SaveChangesWithRetries(SaveChangesOptions.Batch); 
        } 

        ctx = new TableServiceContext(acct.TableEndpoint.AbsoluteUri, acct.Credentials); 
       } 
       TestEntity entity = new TestEntity(i); 
       testEntities.Add(entity); 
       ctx.AddObject("Test", entity); 
      } 

      ctx.SaveChangesWithRetries(SaveChangesOptions.Batch); 

      ctx = new TableServiceContext(acct.TableEndpoint.AbsoluteUri, acct.Credentials); 

      List<TestEntity> retrievedEntities = (from r in ctx.CreateQuery<TestEntity>("Test") 
                select r).AsTableServiceQuery().ToList(); 

      Assert.AreEqual(testEntities.Count, retrievedEntities.Count); 
      Console.Out.WriteLine(retrievedEntities.Count); //prints 2000 

      foreach (var insertedEntity in testEntities) 
      { 
       TestEntity retrievedEntity = retrievedEntities.First(r => r.RowKey == insertedEntity.RowKey); 
       Assert.NotNull(retrievedEntity); 
      } 
     } 

     public class TestEntity : TableServiceEntity 
     { 
      public TestEntity() 
      { 
      } 

      public TestEntity(int id) 
       : base("Test", id.ToString()) 
      { 

      } 
     } 
+0

所以你說'CloudTableQuery'本地處理延續令牌?你能告訴我一些關於ti的參考嗎?如果是這樣,那麼我已經被覆蓋了。 – 2012-02-24 20:49:42

+1

我找不到任何真正好的參考,但寫了一些示例代碼來證明這一點並添加它。 – 2012-02-24 22:02:23

1

它提到的文本中檢查出http://blogs.msdn.com/b/windowsazurestorage/archive/2010/07/09/understanding-windows-azure-storage-billing-bandwidth-transactions-and-capacity.aspx

表查詢 - 當您查詢使用CloudTableQuery它需要照顧 處理延續令牌,所以它使用receieved的 延續標記補發查詢先前的查詢請求獲得 剩下的實體。如上所述,對服務的每個重新發行的延續 令牌查詢計爲1個事務。

而且http://blogs.msdn.com/b/jimoneil/archive/2010/10/05/azure-home-part-7-asynchronous-table-storage-pagination.aspxhttp://scottdensmore.typepad.com/blog/2010/04/paging-with-windows-azure-table-storage.html

相關問題