删除 Azure Table 存储中的实体属性

Remove EntityProperties in Azure Table Storage

我正在尝试创建自己的 TableEntity 以在字典样式中动态添加 EntityProperties。 到目前为止,为了存储、读取和更新,诀窍是覆盖或实现以下功能。

ReadEntity(IDictionary<string, EntityProperty> properties, OperationContext operationContext)

IDictionary<string, EntityProperty> WriteEntity(OperationContext operationContext)

但是,我无法从 Azure Table 存储中的行中删除 EntityProperty。 例如,我的 table 存储中有一行包含以下额外的 属性:

name:string

当检索 属性(例如 ReadEntity)时,我从我的 Table 存储中获取了那个 EntityProperty。 我的印象是,我通过 WriteEntity 的所有内容最终都会进入 table 存储空间。但是例如,当我 return 一个 WriteEntity 的空字典时,我在 table 存储中的实体保持不变。我希望如果我在 merge 期间不提供 EntityProperty,那么 EntityProperties 将从该行的 Table 存储中删除。

当我有更多额外的属性时,例如nameaddress,我在调用 WriteEntity 函数时删除 name 并更新 address,更新 addressname保持不变而不是删除。

tldr:如何以编程方式从 Table 实体中删除 EntityProperty,以便将其从 Table 存储中删除?

I would expect that if i supply no EntityProperty during a merge, the EntityProperties are deleted from the Table Storage for that row.

相信大家对merge的操作存在一些误解。合并操作只会更改请求中包含的属性。如果实体中存在但合并请求中不存在的属性,则该属性将保持不变。

如果要从实体中完全删除属性,您需要使用 replace 操作而不是 merge 操作。在替换操作的情况下,实体将替换为您在请求中传递的实体。因此它将仅具有您在替换操作请求中指定的那些属性。

来自 Merge Entity REST API 文档:

A property cannot be removed with a Merge Entity operation. To remove a property from an entity, replace the entity by calling the Update Entity operation.