user981375
user981375

Reputation: 647

Using TransformResults to select hierarical data from RavenDB?

I have a simple class hierarchy looking like this:

public class Top
{
    public string Id { get; set; }
    public string Description { get; set; }
    public List<Middle> Middles { get; set; } 
}

public class Middle
{
    public string Id { get; set; }
    public string Description { get; set; }
    public List<Bottom> Bottoms { get; set; } 
}

public class Bottom
{
    public string Id { get; set; }
    public string Description { get; set; }
}

The whole thing is saved as entity of type 'Top'. Document is designed to preserve and reflect relationships/hierarchy but half but at time I will, for example, care only about an 'Id' and 'Description' of a given relationship. So, the types of queries I'd want to run are

I would like the results to be transformed and returned to me like this:

public class Result
    {
        public int Id { get; set; }
        public string Description { get; set; }
    }

How can I implement TransformResults (I presume that that's the feature that can be used) to achieve this? I've read quite a few examples but all of the sudden I see parameters/values, which were not declared anywhere and as a result I don't understand what's happening.

Upvotes: 2

Views: 187

Answers (1)

Ayende Rahien
Ayende Rahien

Reputation: 22956

TransformResults doesn't have access to the outside world, you can't execute logic based on the query that you run. You can flatten this structure, sure, but unless you will create multiple indexes with different TransformResults, you can't do this. Note that this is a strange thing to do in the first place, because it doesn't matches the standard modeling of documents as a transaction boundary.

Upvotes: 1

Related Questions