gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 17:01:07 26 4
gpt4 key购买 nike

我有以下代码,它尝试更新以下恰好包含 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 时进行更新时,我收到带有 Message =“NotImplemented”的 StorageException。除了将 DateTimeOffset 序列化\反序列化为字符串之外,我还有其他选择吗?

最佳答案

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

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

关于c# - 使用 DateTimeOffset 更新 Azure 表 TableEntity 会引发 NotImplemented 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21421862/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com