Taking the Stack Overflow tagging system as the canonical example, how can I get back a tag object with its count?
Given these entities:
// Represents the data from the TagCount index
public class TagCount
{
public string Tag { get; set; }
public int Count { get; set; }
}
// Represents the data used to populate a tag-wiki
public class Tag
{
public string Tag { get; set; }
public DateTime Created { get; set; }
public string Description { get; set; }
}
public class Question
{
// elided
public List<string> Tags { get; set; }
// elided
}
And the following definition of the TagCount index
// Map
from question in docs.Questions
from Tag in question.Tags
select new { Tag, Count = 1 }
// Reduce
from result in results
group result by result.Tag into g
select new
{
Tag = g.Key,
Count = g.Sum(x=>x.Count)
}
On the tags page (e.g. https://stackoverflow.com/tags) we need to display a combination of the Tags collection and the TagCounts index. That is, we need to display the Tag.Name and Tag.Description from the Tags collection and TagCount.Count from the TagCount index. In SQL Server this would be achieved by a join, but this is obviously the relational way of thinking. What is the idiomatic RavenDB way of achieving this?
Is there a way to add a Count property to the Tag entity and have the index automatically update that property?