RavenDB: indexing documents from multiple collections

I have several collections of documents that sometimes need to be combined into one index for reporting purposes.

This FAQ provides a solution for writing such an index in Raven Studio: http://ravendb.net/faq/indexing-across-entities

Although I understand that I am not getting a full compile time check, I am trying to avoid completely uncontrolled code as follows:

public class Assets_ById : AbstractIndexCreationTask { public override IndexDefinition CreateIndexDefinition() { return new IndexDefinition { Map = @"from doc in docs where doc[""@metadata""][""Raven-Entity-Name""] == ""Cars"" || doc[""@metadata""][""Raven-Entity-Name""] == ""Trains"" || doc[""@metadata""][""Raven-Entity-Name""] == ""Boats"" || doc[""@metadata""][""Raven-Entity-Name""] == ""Planes"" select new { Cost = doc.Cost, Id = doc.Id, Name = doc.Name, Type = doc.Type, };" } } } 

Is there something similar to the general AbstractIndexCreationTask<T> that will allow me to define a heterogeneous index with lambda expressions?

+6
source share
2 answers

Take a look here: https://groups.google.com/forum/#!topic/ravendb/9wvRY0OiGBs

Basically the same question and short answer:

"right now there’s no better option, but there will be

+4
source

You can use WhereEntityIs (names), for example:

 from doc in docs.WhereEntityIs<Vehicle>("Cars", "Trains", "Boats", "Planes") select new { doc.Cost, doc.Name, doc.Type } 
+5
source

Source: https://habr.com/ru/post/895590/


All Articles