无法查询 Table 存储中的 DateTime 列

Cannot query a DateTime column in Table Storage

我在逻辑应用程序中使用 formatDateTime() 将一列插入到 table 存储中,并输入了正确的值,当我查看记录时列类型显示为 DateTime:

然而,当我尝试查询此字段时,它默认为字符串,即使我将其更改为 DateTime,它 returns 也没有结果。

我在 formatDateTime() 中尝试了不格式化、标准格式和自定义格式,但没有任何结果会返回。关于我遗漏了什么有什么想法吗?

根据一些测试,该值仍然是“String”类型,而不是“DateTime”类型。 document 向我们展示了方法 formatDateTime() 响应字符串中的值。

所以当我们从方法 formatDateTime() 中插入值时,它会将一个字符串插入到存储 table 中。天蓝色门户的显示似乎有一个错误,它显示类型是“DateTime”。但是如果我们在“Azure Storage Explorer”中打开table存储而不是在Azure portal上,我们可以发现新插入记录的TimeOfCreation在“String" 类型。

对于这个需求,很难在逻辑应用程序中获取一个“DateTime”类型的值并将其插入到table存储中。我们可以只插入一个字符串。但是我们可以在将新记录插入到 table 存储后编辑类型。我们可以在 Azure 门户或“Azure 存储资源管理器”中执行此操作。如果在 Azure 门户上执行,只需单击“edit”记录,然后单击“Update”按钮而不执行任何操作(因为类型已经显示为“约会时间”)。如果在“Azure Storage Explorer”中执行,只需将类型从“String”更改为“DateTime[=41=” ]”并单击“更新”。之后,我们可以通过“TimeOfCreation”查询记录 >= Last 365 days success.

不好的是,我们只能在每条插入的记录上手动执行。我们无法在逻辑应用程序或批量更新类型(在门户或资源管理器中)中解决此问题。如果要批量更新类型,可以通过这个api (use $filter to filter timestamp). And then get each record's PartitionKey and RowKey, and loop them. Use this api查询所有新插入的记录来更新列TimeOfCreation类型。

要插入 DateTime 类型的日期,请使用 odata.type 属性(参考下面的示例)并且有效。

{  
   "Address":"Mountain View",  
   "Age":23,  
   "AmountDue":200.23,  
   "CustomerCode@odata.type":"Edm.Guid",  
   "CustomerCode":"c9da6455-213d-42c9-9a79-3e9149a57833",  
   "CustomerSince@odata.type":"Edm.DateTime",  
   "CustomerSince":"2008-07-10T00:00:00",  
   "IsActive":true,  
   "NumOfOrders@odata.type":"Edm.Int64",  
   "NumOfOrders":"255",  
   "PartitionKey":"mypartitionkey",  
   "RowKey":"myrowkey"  
}

参考:

https://docs.microsoft.com/en-us/rest/api/storageservices/understanding-the-table-service-data-model#property-types

https://docs.microsoft.com/en-us/rest/api/storageservices/inserting-and-updating-entities