user516883
user516883

Reputation: 9408

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

Upvotes: 3

Views: 285

Answers (2)

Matt Johnson-Pint
Matt Johnson-Pint

Reputation: 241959

Either are acceptable. Alonso is right though, wait until you have a compelling reason to separate it.

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.

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.

Upvotes: 4

Alonso Robles
Alonso Robles

Reputation: 401

Store the list within the containing object/document. Unless you have a really compelling reason to do otherwise.

Upvotes: 4

Related Questions