简体   繁体   English

RavenDB模型设计一对多

[英]RavenDB model Design one to many

If I have an object that has a list. 如果我有一个包含列表的对象。 Should I store that list in the same document as the object or store that list in a separate document with a reference. 我是否应该将该列表存储在与列表中的对象或存储相同的文档中,并带有引用。 Or should I store it in both, Also not that the photo list object size will increase, thanks for any advice. 或者我应该将它存储在两者中,也不是说照片列表对象的大小会增加,感谢任何建议。

public class Album
{
    public string Name { get; set; }

    //Should I store this inside of the album document?
    public List<Photo> Photos {get; set; } 
}

public class Photo
{
    public string Title { get; set; }
}

Store the list within the containing object/document. 将列表存储在包含的对象/文档中。 Unless you have a really compelling reason to do otherwise. 除非你有一个非常令人信服的理由否则。

Either are acceptable. 要么是可以接受的。 Alonso is right though, wait until you have a compelling reason to separate it. Alonso是对的,等到你有令人信服的理由把它分开。

Example of a compelling reason would be if you frequently need access to the rest of the album information and the photos list was very large. 一个令人信服的理由的例子是,如果您经常需要访问其余的专辑信息,并且照片列表非常大。 Another example is if you wanted version tracking on the Album but not on the Photos list. 另一个例子是,如果您想要在相册上进行版本跟踪,而不是在照片列表上进行。

A third possibility would be to store each Photo in a separate document and reference the Album id instead of keeping a list at all. 第三种可能性是将每张照片存储在单独的文档中,并引用相册ID而不是保留列表。

public class Photo
{
    public string Id { get; set; }
    public string Title { get; set; }
    public string AlbumId { get; set; }
}

It really just depends on what works better for your scenario. 它实际上取决于哪种方案更适合您的场景。 There is no one right way. 没有一个正确的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM