29

このようなクラスがある場合:

    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 属性がありますか、または代わりにそれらの関係を提供する継承されたクラスを作成する必要がありますか?

4

5 に答える 5

4

bwc の Andy Cross からの返信 --- Andy さん、ありがとうございます。 この質問は紺碧のフォーラムです

やあ、

WritingEntity および ReadingEntity イベントを使用します。http://msdn.microsoft.com/en-us/library/system.data.services.client.dataservicecontext.writingentity.aspxこれにより、必要なすべての制御が可能になります。

参考までに、ここにもリンクされているブログ投稿があります

ありがとうアンディ

于 2010-02-18T15:53:19.217 に答える
3

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
{
}

利用方法

public class MyEntity : CustomTableEntity
{
     public string MyProperty { get; set; }

     [NonSerializedOnAzure]
     public string MyIgnoredProperty { get; set; }
}
于 2013-04-19T11:14:14.723 に答える