如何将属性排除在Azure表存储中的持久化?

如何将属性排除在Azure表存储中的持久化?,azure,azure-storage,azure-table-storage,Azure,Azure Storage,Azure Table Storage,如果我有这样一门课: public class Facet : TableServiceEntity { public Guid ParentId { get; set; } public string Name { get; set; } public string Uri{ get; set; } public Facet Parent { get; set; } } Parent是从ParentId Guid派生的,该关系将由我的存储库

如果我有这样一门课:

    public class Facet : TableServiceEntity
{
    public Guid ParentId { get; set; }      
    public string Name { get; set; }
    public string Uri{ get; set; }
    public Facet Parent { get; set; }
}

Parent是从ParentId Guid派生的,该关系将由我的存储库填充。那么,我该如何让Azure离开该领域呢?是否存在某种类型的Ignore属性,或者我必须创建一个继承类来提供这些关系?

这是来自bwc的Andy Cross的回答---再次感谢Andy。

使用WritingEntity和ReadingEntity事件。这将为您提供所需的所有控制

作为参考,这里也链接了一篇博文:

谢谢
Andy

您可以覆盖TableEntity中的WriteEntity方法,并删除任何具有自定义属性的属性

public class CustomTableEntity : TableEntity
{
    public override IDictionary<string, EntityProperty> WriteEntity(Microsoft.WindowsAzure.Storage.OperationContext operationContext)
    {
        var entityProperties = base.WriteEntity(operationContext);
        var objectProperties = GetType().GetProperties();

        foreach (var property in from property in objectProperties 
                                 let nonSerializedAttributes = property.GetCustomAttributes(typeof(NonSerializedOnAzureAttribute), false) 
                                 where nonSerializedAttributes.Length > 0 
                                 select property)
        {
            entityProperties.Remove(property.Name);
        }

        return entityProperties;
    }
}

[AttributeUsage(AttributeTargets.Property)]
public class NonSerializedOnAzureAttribute : Attribute
{
}

可以在要排除的属性上设置名为WindowsAzure.Table.Attributes.IgnoreAttribute的属性。只需使用:

[忽略]
公共字符串MyProperty{get;set;}
它是Windows Azure存储扩展的一部分,您可以从以下位置下载:

或作为软件包安装:

该库已获得MIT许可。

使用最新SDK(v6.2.0及更高版本),属性名称已更改为
IgnorePropertyAttribute

公共类MyEntity:TableEntity
{
公共字符串MyProperty{get;set;}
[不动产]
公共字符串MyIgnoredProperty{get;set;}
}

遗憾的是,到论坛的链接不再有效:-(MSDN真的把链接搞砸了!他们现在这样做了,这已经被
IgnorePropertyAttribute
取代,请参阅。
public class MyEntity : CustomTableEntity
{
     public string MyProperty { get; set; }

     [NonSerializedOnAzure]
     public string MyIgnoredProperty { get; set; }
}