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

问题描述 投票:2回答:1

我已经在互联网上搜索过,并且我的问题的每个可能答案都不在C#中,或者在我的RavenDB版本中不可用。 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; }
}

我想要一个返回如下内容的索引:

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版中,转换器需要自己位于一个类中,我似乎找不到如何使用数据库从FirstDocumentType中的ID提取SecondDocumentType的方法。委托函数仅接受1个参数,即文档类型。

c# nosql ravendb
1个回答
1
投票

您认为可以在此测试存储库中找到所需的语法:

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

© www.soinside.com 2019 - 2024. All rights reserved.