2010-02-16 3 views
19

나는이 같은 클래스가있는 경우 :Azure 테이블 저장소에서 속성이 지속되지 않도록 어떻게 제외합니까?

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

부모가 ParentId 가이 드에서 파생되고, 그 관계는 저장소 (repository)에 의해 작성하기위한 것입니다를. 그렇다면 아저르에게 그 밭을 내버려 두라고 어떻게 말합니까? 어떤 유형의 Ignore 속성이 있습니까? 아니면 그 관계를 대신 제공하는 상속 된 클래스를 만들어야합니까?

+0

그들은 지금 http://stackoverflow.com/questions/5379393/do-azure-table -services-entities-has-an-non-serialized 속성을 가지고 있습니다. –

답변

4

앤디 크로스 (Andy Cross)에서 bwc로 회신드립니다. 다시 한 번 감사드립니다. This question an azure forums

안녕,

는 WritingEntity 및 ReadingEntity 이벤트를 사용합니다. http://msdn.microsoft.com/en-us/library/system.data.services.client.dataservicecontext.writingentity.aspx 필요한 모든 기능을 제공합니다. 참고로

여기 너무 떨어져 링크 된 블로그 게시물있다 : http://social.msdn.microsoft.com/Forums/en-US/windowsazure/thread/d9144bb5-d8bb-4e42-a478-58addebfc3c8

감사에게 앤디

+2

슬프게도 포럼에 대한 링크가 더 이상 작동하지 않습니다 :-(MSDN은 정말로 링크를 망쳤습니다! –

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; } 
} 
8

제외 할 속성을 설정할 수 있습니다 WindowsAzure.Table.Attributes.IgnoreAttribute라는 속성이 있습니다. 그냥 사용 https://github.com/dtretyakov/WindowsAzure

또는 패키지로 설치 : https://www.nuget.org/packages/WindowsAzure.StorageExtensions/

라이브러리는 MIT 라이센스가

[Ignore] 
public string MyProperty { get; set; } 

그것은 당신이에서 다운로드 할 수 있습니다 윈도우 Azure 스토리지 확장의 일부입니다. (최대 v6.2.0와) 최신 Microsoft.WindowsAzure.Storage SDK를 사용하여

+3

이것은 이후에 'IgnorePropertyAttribute'로 대체되었습니다. [IgnorePropertyAttribute 클래스] (https://msdn.microsoft.com/en-us/library/microsoft.windowsazure.storage.table.ignorepropertyattribute.aspx). – Aaron

15

, 속성 이름은 IgnorePropertyAttribute로 변경되었습니다

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

    [IgnoreProperty] 
    public string MyIgnoredProperty { get; set; } 
} 
관련 문제