如何制作一个索引来模拟与 RavenDB 3.5 的内部连接?

How can I make an Index that simulates an inner join with RavenDB 3.5?

我在 Internet 上搜索过,我的问题的每个可能答案要么不在 C# 中,要么在我的 RavenDB 版本中不可用。

我想对 2 种不同的文档类型进行最简单的内部联接。 (我知道这是一个基于文档的数据库,而不是一个关系数据库,但我不对当前的模型化负责)

假设我有这两种不同的文档类型:

public class FirstDocumentType
{
    public string Id { get; set; }

    public string FirstDocumentTypeProperty { get; set; }

    public string SecondDocumentTypeId { get; set; }
}

public class SecondDocumentType
{
    public string Id { get; set; }

    public string SecondDocumentProperty { get; set; }
}

我想要一个 returns 像这样的索引:

public class IndexResult
{
    public string FirstDocumentTypeId { get; set; }

    public string SecondDocumentTypeId { get; set; }

    public string FirstDocumentTypeProperty { get; set; }

    public string SecondDocumentProperty { get; set; }
}

如何使用 C# 实现?

对于 3.5 之前的 RavenDB 版本3.x,我知道可以使用索引构造函数中的转换结果来实现这一点,如下所示:

          TransformResults =
                (database, firstDocumentTypes) => from firstDocumentType in firstDocumentTypes
                    let secondDocumentType = database.Load<SecondDocumentType>(firstDocumentType.SecondDocumentTypeId)
                    select new
                    { 
                        FirstDocumentTypeId = firstDocumentType.Id,
                        SecondDocumentTypeId = secondDocumentType.Id,
                        firstDocumentType.FirstDocumentTypeProperty,
                        secondDocumentType.SecondDocumentProperty 
                    };

现在,在 3.5 版中,转换器需要单独位于 class 中,我似乎无法找到如何使用数据库从 FirstDocumentType 中的 ID 获取 SecondDocumentType。委托函数只接受 1 个参数,即文档类型。

编辑:我实际上在文档中找到了答案 https://ravendb.net/docs/article-page/3.5/csharp/transformers/loading-documents

我只是很难在其中导航...

我认为您正在寻找的语法可以在此测试存储库中找到:

https://github.com/ravendb/ravendb/blob/v3.5/Raven.Tests/Indexes/TransformerParameterTest.cs

任何想知道 AbstractTransformerCreationTask 中有一个名为 "LoadDocument" 的函数的人。

可以用来模拟INNER JOIN。就这么简单...

我实际上在文档中找到了我的答案https://ravendb.net/docs/article-page/3.5/csharp/transformers/loading-documents

我只是很难在其中导航...