2017-08-05 54 views
1

我已經存儲在Azure Table中的一些枚舉這樣使用Array或List屬性創建TableEntity?

pk rk | en  fr  de ... 

foo 1 | 'Eune' 'Fune' 'Dune' ... 
foo 2 | 'Edoe' 'Fdoe' 'Ddoe' ... 

bar 1 | 'Unee' 'Unef' 'Trid' ... 
bar 2 | 'Diee' 'Dief' 'Died' ... 
bar 3 | 'Trie' 'Tref' 'Trid' ... 

enfrde等等都是語言代碼,並分別在表中的列名。

我應該爲了創造什麼樣的TableEntity加載它正確

public class FooEntity : TableEntity 
{ 
    public Dictionary<string, string> Descriptions {get; set} // ? 
} 

,然後用它們像myFoo["fr"] ...這可能嗎?

說我有英文GUI,我需要顯示一個Foo選擇​​/Edoe作爲選擇值。

回答

1

Azure存儲表不支持Array,List或Dictionary作爲實體屬性。您可以找到所有支持的屬性類型here(「屬性類型」部分)。但是,您可以考慮將數組/列表/字典序列化爲字符串屬性,並在TableEntity類中使用[IgnoreProperty]屬性聲明屬性以將序列化字符串轉換回數組/列表/字典。

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

    [IgnoreProperty] 
    public Dictionary<string, string> DicProperty 
    { 
     get 
     { 
      return Deserialize(DicPropertyRaw); 
     } 

     set 
     { 
      DicPropertyRaw = Serialize(value); 
     } 
    } 
}