c# - 如何使用 RavenDB 3.5 创建一个模拟内部连接的索引?
问题描述
我搜索了互联网,我的问题的每个潜在答案要么不在 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; }
}
我想要一个返回如下内容的索引:
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,我知道可以使用 Index 构造函数中的转换结果来做到这一点,如下所示:
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 个参数,即文档类型。
编辑:我实际上在文档https://ravendb.net/docs/article-page/3.5/csharp/transformers/loading-documents中找到了我的答案
我只是很难在其中导航...
解决方案
我认为您正在寻找的语法可以在这个测试存储库中找到:
https://github.com/ravenb/ravenb/blob/v3.5/Raven.Tests/Indexes/TransformerParameterTest.cs
推荐阅读
- c++ - 关于标准容器内边界检查的问题
- tensorflow - 资源调用 close -flutter/tflite 错误失败
- android - Android更改搜索栏颜色
- django - Django csrf_protect 装饰器不起作用
- .net - 如何在 WCF 服务中显示自定义错误页面
- ruby-on-rails - 为什么我的使用 Factory Bot 的协会不起作用?
- python - 如何更改我的代码以仅打印 x 数量的图表?
- pine-script - 使用 Pine 脚本是否可以将某些文件中的一些外部数据添加到 TradingView 图表?
- openvas - OpenVAS 安装和运行错误
- java - 带有非 UTF-8 字符的请求正文引发 JSON 解析错误:无效的 UTF-8 起始字节 0xae , 0xfc