【问题标题】:How to create composite key at ArrangoDB如何在 ArangoDB 创建复合键
【发布时间】:2016-12-01 02:43:13
【问题描述】:

我在 C# 中使用了 ArangoDB.Client。 我正在创建一个资源类并将 ResourceId 和 Locale 作为复合键。

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

请提出任何其他想法!

【问题讨论】:

  • ResourceId type 是 Guid 本身就已经是独一无二的了,为什么还要和Locale结合呢?

标签: c# arangodb composite-key


【解决方案1】:

ArangoDB 键只能在一个名为 _key 的属性上设置。使用 c# 客户端,您只能指定应将哪个类成员转换为 _key 属性。

我自己没有这样做,但您可以连接 ResourceIdLocale 并将其设置为 Key(请注意密钥长度最多应为 254 个字节)

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

或者,如果您希望这些字段对于每个文档都是唯一的,您可以在 ResourceIdLocale 上创建唯一的哈希索引,并将它们作为普通属性。

【讨论】:

    猜你喜欢
    • 2020-03-23
    • 2019-04-20
    • 1970-01-01
    • 1970-01-01
    • 2020-08-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-23
    • 1970-01-01
    相关资源
    最近更新 更多