2014-01-29 27 views
3

我有下面的代码,它尝试更新下面的实体类,它恰好包含DateTimeOffset,但是会引发NotImplementedException。有其他人看过吗?使用DateTimeOffset更新Azure表TableEntity抛出NotImplemented异常

[System.Data.Services.Common.DataServiceKey("PartitionKey", "RowKey")] 
public sealed class CollectorStateEntity : TableEntity 
{ 
    public CollectorStateEntity() 
    {} 

    public CollectorStateEntity(string collectorName, string tenantInstance) 
    { 
     this.PartitionKey = tenantInstance; 
     this.RowKey = collectorName; 
    } 

    public DateTimeOffset StartingTime { get; set; } 
} 


    public static void UpdateCollectorStateEntityInTableStore(string connectionString, string tableName, string tenantInstance, string collectorName) 
    { 
     // Get Access to the table 
     CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString); 
     CloudTableClient tableClient = storageAccount.CreateCloudTableClient(); 
     TableServiceContext serviceContext = tableClient.GetTableServiceContext(); 


     CollectorStateEntity specificEntity = 
      (from e in serviceContext.CreateQuery<CollectorStateEntity>(tableName) 
      where e.PartitionKey == tenantInstance && e.RowKey == collectorName 
      select e).FirstOrDefault(); 

     specificEntity.StartingTime = DateTimeOffset.Parse("01/27/2014 10:35:00 AM -08:00"); 

     serviceContext.UpdateObject(specificEntity); 
     serviceContext.SaveChangesWithRetries(); 
    } 

当试图调用UpdateCollectorStateEntityInTableStore时做一个更新我得到消息=“NotImplemented”一StorageException。除序列化\将DateTimeOffset反序列化为字符串外,还有其他选项吗?

+0

是否支持Azure的DateTimeOffset?根据http://msdn.microsoft.com/en-us/library/windowsazure/jj553018.aspx它不是? –

+0

你是对的,但是插入和删除包含DateTimeOffset的实体工作正常,看起来团队只是没有实现更新。感谢指针。 – arunsun

回答

2

正如Brendan所述,因为DateTimeOffset不是Azure表存储中受支持的数据类型,所以出现此错误。有几件事情你可以做的是:

  1. 正如你所说,你可以使用,而不是一个DateTimeOffsetString类型DateTime财产。
  2. 另一种选择是自己进行序列化/反序列化。为此,您需要覆盖ReadEntityWriteEntity方法。