简体   繁体   English

忽略 null 属性 Azure 表存储

[英]Ignore null properties Azure Table Storage

The admins for my application can make extra properties for the userprofiles.我的应用程序的管理员可以为用户配置文件创建额外的属性。 So UserA can have 1 Cellphone number, while UserB can have 5. Or UserA can have a Creditcard number while UserB doesn't have any.所以用户A可以有1个手机号码,而用户B可以有5个。或者用户A可以有一个信用卡号码,而用户B没有。

I want to make this work with Azure Table Storage.我想使用 Azure 表存储来完成这项工作。 I'm making generic entities and inserting them into Table Storage.我正在制作通用实体并将它们插入到表存储中。

I know every entity/row can only have 255 filled in properties ( Partition Key, Row Key, Timestamp and your own properties.) In my situation there is a high chance there will be more columns but a very very small chance 1 user will actually use 255 properties.我知道每个实体/行只能有 255 个填充属性(分区键、行键、时间戳和您自己的属性。)在我的情况下,很有可能会有更多的列,但实际上只有一个用户的可能性很小使用 255 个属性。

Now here is the problem, when the user reads his entity all the other properties that he doesn't use will be 'm:null="true' .现在问题来了,当用户读取他的实体时,他不使用的所有其他属性将是'm:null="true'

As you can see he still takes the extra properties he doesn't need.正如你所看到的,他仍然拥有他不需要的额外属性。 I can of course ignore them in my ReadingEntity Event but it's still overhead right?我当然可以在我的ReadingEntity事件中忽略它们,但它仍然是开销,对吗? Imagine you want to get the profiles of 100 users and you have like 500 columns.想象一下,您想要获取 100 个用户的个人资料,并且您有大约 500 个列。 There will be a lot of useless data in that xml file & network traffic. xml 文件和网络流量中会有很多无用的数据。

Is there any way to ignore those null and don't send them back at all?有什么办法可以忽略那些 null 并且根本不将它们发回吗? Instead of sending them back and marking the column as null?而不是将它们发回并将列标记为 null?

在此处输入图像描述

And are you using development storage?你在使用开发存储吗? Make sure to try this against real cloud storage... dev storage saves an actual schema and may be applying properties from other entities to the one you're trying to read.确保针对真正的云存储尝试此操作...开发存储保存了一个实际的模式,并且可能会将其他实体的属性应用于您尝试读取的实体。 – smarx Jul 5 at 17:28 – smarx 7 月 5 日 17:28

This was the solution这是解决方案

When you are saving an entity, are you saving these extra properties (with null value) as well?当您保存实体时,您是否也保存了这些额外的属性(具有 null 值)? As far as Cloud Storage is concerned, if you don't provide an attribute while saving an entity, you will not get that attribute back when fetching entity.就云存储而言,如果您在保存实体时不提供属性,则在获取实体时将无法取回该属性。 However working with development storage is another story all together.然而,使用开发存储是另一回事。 There if you have saved an entity with say 3 custom attributes and another entity with 5 custom attributes.如果您保存了一个具有 3 个自定义属性的实体和另一个具有 5 个自定义属性的实体。 When you fetch the entity, you will get all attributes back.当您获取实体时,您将获取所有属性。

The only way you will see null things returned to you is if you saved them to begin with.您将看到 null 东西返回给您的唯一方法是,如果您从一开始就保存它们。 I would check again your generic entity persistence code or your generic entity itself.我会再次检查您的通用实体持久性代码或您的通用实体本身。 It must be the case there are null values being sent for saving.必须是发送 null 值以进行保存的情况。 Since there is no schema in table storage, it is impossible for it to to send values for fields it doesn't know about.由于表存储中没有模式,因此它不可能为它不知道的字段发送值。 Fiddler will show you for sure on a save. Fiddler 肯定会在保存时向您展示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM