且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何向保存在 Azure 表存储中的实体添加新属性?

更新时间:2023-12-01 08:25:28

我假设您使用的是 .NET,因为您提到了映射到表中实体的类.表存储本身没有架构,所以这完全不是问题.

I'm assuming you're using .NET, because you mentioned classes mapping to entities in tables. Table storage itself has no schema, so this is a complete non-issue.

在没有架构的情况下使用 WCF 数据服务客户端库(位于 Microsoft.WindowsAzure.Storage 下的内容)有点棘手.搜索与表存储相关的 ReadingEntityWritingEntity,您可能会找到所需的内容.本质上,您需要挂钩这些事件并解析(或注入)您想要的额外属性.人们通常通过创建一个字典属性来处理这些额外"属性,然后在这些事件触发时读取和写入它们.

Using the WCF Data Services client library (what's underneath Microsoft.WindowsAzure.Storage) without a schema is a bit tricky. Search for ReadingEntity and WritingEntity relating to table storage, and you'll probably find what you need. Essentially, you need to hook these events and parse (or inject) the extra properties you want. People usually do this by creating a dictionary property to handle those "extra" properties and then read and write them when those events fire.

您还可以查看 http://www.lucifure.com/,这是一个替代客户端库,我没有经验.我相信它也解决了这个限制:通过字典动态存储,因此您不必将每个表属性映射到类成员."

You might also check out http://www.lucifure.com/, an alternative client library that I have no experience with. I believe it addresses this limitation too: "Dynamic stashing via a dictionary, so you do not have to map every table property to a class member."