如何向保存在 Azure 表存储中的实体添加新属性? [英] How to add new properties to an entity saved in Azure Table Storage?

查看:14
本文介绍了如何向保存在 Azure 表存储中的实体添加新属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个应用程序,其中从 TableServiceObject 派生的 .NET 类型保存到 Azure 表存储(称为Person")具有另一个实体(事件")的集合.当然,集合属性不会保存到 Azure 表存储.

I am working with an application where a .NET type derived from TableServiceObject being saved to Azure Table Storage (call it "Person") has a collection of another entity ("events"). Of course, the collection property doesn't save to Azure Table Storage.

我想做的是在 Person 存储实体上拥有可变数量的属性,并在必要时创建一个新属性.例如,如果 Person1 之前参加过 1 个活动,并且参加了一个新活动,我的代码需要为 Person1 实体创建一个Event2"属性,并将指向 Event2 存储位置的指针保存在该属性中.Person1 然后有 2 个事件"属性,但该表中的另一个实体可能有 10 个(event1、event2、event3 ... event10).

What I would like to do is have a variable number of properties on a Person storage entity, and create a new property whenever necessary. For example, if Person1 has attended 1 event before, and attends a new event, my code needs to go create an "Event2" property for the Person1 entity, and save the pointer to the storage location of Event2 in that property. Person1 then has 2 "event" properties, but another entity in that table may have 10 (event1, event2, event3 ... event10).

因为 Person 类直接映射到 Azure Tables,它会自动为类中的每个公共属性创建一个属性,所以我找不到在不创建永久属性的情况下将 Event2 属性动态添加到这个保存的实体的方法在我的课上,我不想这样做.有办法吗?

Because the Person class is mapped directly to the Azure Tables, which automatically creates a property for every public property in the class, I can't find a way to dynamically add the Event2 property to this saved entity without creating a permanent property on my class, which I don't want to do. Is there a way?

想要存储这组参差不齐"的属性的目的是让我能够获取一个人去过的所有事件,而无需对存储事件的分区进行完整扫描.

The purpose of wanting to store this "jagged" set of properties is to allow me to go get all the events a person has been to, without doing an entire scan on the partition where the events are stored.

谢谢!

更新:Smarx 是正确的 - 一旦我知道要查找什么,就很容易找到有关如何在 Azure 表服务中使用 ReadingEntity 和 WritingEntity 事件的描述:http://convective.wordpress.com/2009/12/30/entities-in-azure-tables/

Update: Smarx was correct - once I knew what to look for, it was easy to find this description of how to use the ReadingEntity and WritingEntity events in the Azure Table Service: http://convective.wordpress.com/2009/12/30/entities-in-azure-tables/

推荐答案

我假设您使用的是 .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."

这篇关于如何向保存在 Azure 表存储中的实体添加新属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆