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

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

问题描述

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

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表,该表自动为该类中的每个公共属性创建一个属性,因此我找不到在不创建永久属性的情况下将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 Table Service中使用ReadingEntity和WritingEntity事件的以下描述: http://convective.wordpress.com/2009/12/30/entity-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天全站免登陆