Azure 表服务实体是否具有相当于 NonSerializedAttribute 的属性?
如果我尝试序列化普通的 CLR 对象,并且不希望序列化特定的成员变量,则可以使用该
[NonSerialized]
属性对其进行标记。如果我要创建表服务实体,是否可以使用等效属性告诉 Azure 表服务忽略此属性?
If I'm trying to serialize a normal CLR object, and I do not want a particular member variable to be serialized, I can tag it with the
[NonSerialized]
attribute. If I am creating a table services entity, is there an equivalent attribute I can use to tell Azure table services to ignore this property?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对于版本 2.1,有一个新的 Microsoft.WindowsAzure.Storage.Table.IgnoreProperty 属性。有关详细信息,请参阅 2.1 发行说明:http://blogs.msdn.com/b/windowsazurestorage/archive/2013/09/07/announcing-storage-client-library-2-1-rtm.aspx。
For Version 2.1 there is a new Microsoft.WindowsAzure.Storage.Table.IgnoreProperty attribute. See the 2.1 release notes for more information: http://blogs.msdn.com/b/windowsazurestorage/archive/2013/09/07/announcing-storage-client-library-2-1-rtm.aspx.
据我所知,没有类似的东西。
这篇文章介绍了如何实现所需的效果 - http://blogs.msdn.com/b/phaniraj/archive/2008/12/11/customizing-serialization-of-entities-in-the-ado -net-data-services-client-library.aspx
或者,如果您可以在您的财产上使用“内部”而不是“公共”,那么当前的 SDK 就不会保留它(但这可能未来会改变)。
There's no equivalent I know of.
This post says how you can achieve the desired effect - http://blogs.msdn.com/b/phaniraj/archive/2008/12/11/customizing-serialization-of-entities-in-the-ado-net-data-services-client-library.aspx
Alternatively, if you can get away with using "internal" rather than "public" on your property then it will not get persisted with the current SDK (but this might change in the future).
对于 Table Storage SDK 2.0 版,有一种新方法可以实现此目的。
您现在可以重写 TableEntity 上的 WriteEntity 方法并删除具有属性的任何实体属性。我从一个为我的所有实体执行此操作的类派生,例如:
然后您可以为您的实体使用此类,例如
For version 2.0 of the Table Storage SDK there is a new way to achieve this.
You can now override the WriteEntity method on TableEntity and remove any entity properties that have an attribute on them. I derive from a class that does this for all my entities, like:
Then you can make use of this class for your entities like