The sample db that comes with RavenDB has Albums document collection, that each have a Genre embedded document in it, like this:
{
... other stuff...
"Genre": {
"Id": "genres/1",
"Name": "Rock"
},
... other stuff...
}
Notice that here the Genre has Id and Name fields.
But when you look at Genre documents, they have Id, Name, and Description fields, like this:
{
"Description": "Rock and Roll is a form of rock music developed in the 1950s and 1960s. Rock music combines many kinds of music from the United States, such as country music, folk music, church music, work songs, blues and jazz.",
"Name": "Rock"
}
How can I model in code so that when I Store() then SaveChanges() that the Genre will be serialized and saved differently (like the example data) when saving its own document versus when saving the Album document and embedding the Genre?
This model will match the ravendb sample data:
Example usage with includes:
The include means that when loading the Genre, there is no db call because it’s already tracked in the session.