RavenDB Transformer Include List of Documents

I'm kinda stuck with using include with RavenDB Transformer. Let's say I have the following document classes:

public class Processor
{
    public string Id { get; set; }
    // other properties
}

public class Job
{
    public string Id { get; set; }
    public string ProcessorId { get; set; }
    // other properties
}

Here is my view model:

public class ProcessorStatsViewModel
{
    public string Id { get; set; }
    public int JobCount { get; set; }
    // other properties
}

In my tranformer, I would like to request a processor document repository and include in the Job Store a search in search of each job with a suitable processor identifier. All the search results that I found describe how to do this when the Processor class has a JobId list. Is there any way to do this in RavenDB?

The transformer I would like could look something like this:

public Processors_StatsViewModel()
{
    TransformerResults = procs => 
        from p in procs
        let jobs = Include<Jobs>(p.Id) // how can i specify something like where p.Id == j.ProcessorId ?
        select new
        {
            p.Id
            JobCount = jobs.Count
            // other stuff
        }
}

All Transformer LoadDocument, Include, and Recurse methods expect the requested class to have a list reference identifier, but in my case it needs the opposite.

Is this something I can do even in RavenDB, or am I missing something?

+4
1

, , . , , , .

- Map/Reduce, Transformer Map/Reduce. , " " , , :

/ , :

public class Jobs_ByProcessor : AbstractIndexCreationTask<Job, Jobs_ByProcessor.ReduceResult>
{
    public class ReduceResult
    {
        public string ProcessorId { get; set; }
        public int JobCount { get; set; }
    }

    public Jobs_ByProcessor()
    {
        Map = jobs => from job in jobs
                      select new ReduceResult
                      {
                          ProcessorId = job.ProcessorId,
                          JobCount = 1
                      };

        Reduce = results => from result in results
                            group result by result.ProcessorId
                                into g
                                select new
                                {
                                    ProcessorId = g.Key,
                                    JobCount = g.Sum(x => x.JobCount)
                                };
    }
}

:

public class ProcessorJobTransformer : AbstractTransformerCreationTask<Jobs_ByProcessor.ReduceResult>
{
    public ProcessorJobTransformer()
    {
        TransformResults = results => from result in results
            let processor = LoadDocument<Processor>(result.ProcessorId)
            select new
            {
                Id = result.ProcessorId,
                Name = processor.Name,
                JobCount = result.JobCount
            };
    }
}

: enter image description here JobCount "" , Name - Transformer ( LoadDocument).

, , Job, .

, !

0

All Articles