使用DateTimeOffset更新Azure表TableEntity会引发NotImplemented异常

时间:2014-01-29 04:05:09

标签: c# azure azure-table-storage

我有以下代码尝试更新碰巧包含DateTimeOffset的以下实体类,但是会抛出NotImplementedException。有没有人见过这个?

[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时尝试进行更新时,我得到一个MessageException,其中Message =“NotImplemented”。除了将DateTimeOffset序列化/反序列化为字符串?

之外,我还有其他选择吗?

1 个答案:

答案 0 :(得分:2)

正如Brendan所提到的,因为DateTimeOffset在Azure表存储中不是受支持的数据类型,所以您收到此错误。你可以做的一些事情是:

  1. 如您所述,您可以使用StringDateTime类型的属性,而不是DateTimeOffset
  2. 另一种选择是自己进行序列化/反序列化。为此,您需要覆盖ReadEntityWriteEntity方法。