[英]How to create composite key at ArrangoDB
I used ArangoDB.Client in C#. 我在C#中使用了ArangoDB.Client。 I am creating a resource class and making ResourceId and Locale as composite key.
我正在创建一个资源类,并使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;}
}
Above class doesn't work. 上课不起作用。 I have to use as below and require to combine ResourceId and Locale to save as key.
我必须按如下方式使用,并要求结合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;}
}
Please advice any other idea! 请提出任何其他建议!
ArangoDB key can only be set on one attribute named _key
. ArangoDB密钥只能在一个名为
_key
属性上设置。 with c# client you can only specify which one of class members should be translate to _key
attribute. 使用c#客户端,您只能指定应将哪个类成员中的一个转换为
_key
属性。
I didn't do this myself but you can concat ResourceId
and Locale
and set it to Key
(just be aware keys should be at most 254 bytes long) 我自己没有这样做,但是您可以将
ResourceId
和Locale
并置并将其设置为Key
(请注意,密钥的最大长度应为254个字节)
public string Key => $"{ResourceId.ToString("N")}_{Locale}";
Or if you want these fields to be unique for each document, you can create a unique hash index on ResourceId
and Locale
and behave them as normal attributes. 或者,如果您希望这些字段对于每个文档都是唯一的,则可以在
ResourceId
和Locale
上创建唯一的哈希索引,并将它们作为普通属性来使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.