2016-12-01 104 views
0

我在C#中使用了ArangoDB.Client。 我正在創建資源類並將ResourceId和Locale設置爲組合鍵。如何在ArrangoDB創建複合鍵

public class Resource 
{ 
    [Key, Column(Order = 1)] 
    public Guid ResourceId {get; set;} 
    [Key, Column(Order = 2)] 
    [MaxLength(5)] 
    public string Locale {get; set;} 
    public string ResourceName {get; set;} 
} 

上課不起作用。我必須按照以下方式使用,並要求將ResourceId和Locale結合起來保存爲關鍵字。

public class Resource 
{ 
    [DocumentProperty(Identifier = IdentifierType.Key)] 
    public string Key { get; set; } 
    public Guid ResourceId {get; set;} 
    [MaxLength(5)] 
    public string Locale {get; set;} 
    public string ResourceName {get; set;} 
} 

請指教任何其他的想法!

+0

''ResourceId''類型是'Guid',它本身已經是唯一的,爲什麼要將它與'Locale'結合呢? –

回答

1

只能在名爲_key的一個屬性上設置ArangoDB密鑰。使用c#客戶端,您只能指定哪一個類成員應該轉換爲_key屬性。

我不這樣做我自己,但你可以Concat的ResourceIdLocale並將其設置爲Key(只是知道密鑰的長度最多254個字節)

public string Key => $"{ResourceId.ToString("N")}_{Locale}"; 

或者,如果你希望這些區域對於每個文檔都是唯一的,您可以在ResourceIdLocale上創建一個唯一的散列索引,並將它們作爲普通屬性進行操作。