Say I have the following documents in RavenDb:
public class TopLevel
{
public string Id { get; set; }
public string Name { get; set; }
}
public class NextLevel
{
public string Id { get; set; }
public string TopLevelId { get; set; }
public string Name { get; set; }
}
public class Leaf
{
public string Id { get; set; }
public string NextLevelId { get; set; }
public string Name { get; set; }
}
And the following viewmodels:
public class TopLevelViewModel
{
public string Id { get; set; }
public string Name { get; set; }
public List<NextLeveViewModell> NextLevels { get; set; }
}
public class NextLevelViewModel
{
public string Id { get; set; }
public string TopLevelId { get; set; }
public string Name { get; set; }
public List<LeafViewModel> Leaves { get; set; }
}
public class LeafViewModel
{
public string Id { get; set; }
public string NextLevelId { get; set; }
public string Name { get; set; }
}
What would be the best way of constructing that view model without making loads of trips to the db and manually collecting / constructing the structure?
Could I use multi-map for this?
Might be a dumb question but I've not used RavenDb in a while! Been doing Android / iPhone dev so a little rusty!
The best idea here would to not have them as separate documents. A single document can contain all of this. In other words, the structure you've described as the view model can be stored directly into the database as your document structure.
Of course, that means that you will always be retrieving the document by the top-level id. Without additional context of what these nodes represent, it's hard to say if that is appropriate or not.
Also, it looks like you are getting good feedback from this thread on the RavenDB Google Group already. Try not to cross-post in the future. If you want something very specific, then StackOverflow is great. If you need more of a general how-to or debate of ideas, then use the Google Group.
If you can edit your question to be more specific, perhaps showing the index and query you are attempting, then I will update accordingly.