使用 RavenDB 从多个字符串数组创建扇出索引时出现编译错误
本文关键字:索引 错误 编译 扇出 创建 RavenDB 数组 字符串 使用 | 更新日期: 2023-09-27 18:34:39
在我的RavenDB中,我的表单上有对象:
{
"Texts1": [
"one two",
"three four"
],
"Texts2": [
"five six",
"seven eight"
],
"Texts3": [
"nine ten",
"eleven twelve"
]
}
为了能够执行我想要的搜索,我正在尝试创建一个扇出索引(请忽略它不一定以良好的方式扩展的事实(:
from doc in docs
from text1 in doc.Texts1
from text2 in doc.Texts2
from text3 in doc.Texts3
select new
{
Text1 = text1,
Text2 = text2,
Text3 = text3
}
尝试将此索引添加到 RavenDB 会导致错误:
vid Raven.Studio.Infrastructure.InvocationExtensions.Catch(Task parent, Func`2 func)
vid Raven.Studio.Models.IndexDefinitionModel.SaveIndexCommand.Execute(Object parameter)
vid System.Windows.Controls.Primitives.ButtonBase.ExecuteCommand()
vid System.Windows.Controls.Primitives.ButtonBase.OnClick()
vid System.Windows.Controls.Button.OnClick()
vid System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
vid System.Windows.Controls.Control.OnMouseLeftButtonUp(Control ctrl, EventArgs e)
vid MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName, UInt32 flags)
Client side exception:
Raven.Abstractions.Exceptions.BadRequestException: Compilation Errors:
Line 31, Position 4: Error CS0307 - egenskap: <>h__TransparentIdentifier0 cannot be used with type arguments
Source code:
using Raven.Abstractions;
using Raven.Database.Linq;
using System.Linq;
using System.Collections.Generic;
using System.Collections;
using System;
using Raven.Database.Linq.PrivateExtensions;
using Lucene.Net.Documents;
using System.Globalization;
using System.Text.RegularExpressions;
using Raven.Database.Indexing;
public class Index_Test2 : Raven.Database.Linq.AbstractViewGenerator
{
public Index_Test2()
{
this.ViewText = @"from doc in docs
from text1 in doc.Texts1
from text2 in doc.Texts2
from text3 in doc.Texts3
select new
{
Text1 = text1,
Text2 = text2,
Text3 = text3
}";
this.AddMapDefinition(docs =>
from doc in docs
from text1 in doc.Texts1
from text2 in doc.Texts2
from text3 in doc.Texts3
select new {
Text1 = text1,
Text2 = text2,
Text3 = text3,
__document_id = doc.__document_id
});
this.AddField("Text1");
this.AddField("Text2");
this.AddField("Text3");
this.AddField("__document_id");
this.AddQueryParameterForMap("__document_id");
this.AddQueryParameterForReduce("__document_id");
}
}
vid System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
vid System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccess(Task task)
vid Raven.Client.Silverlight.Connection.HttpJsonRequest.<ReadResponseJsonAsync>d__2.MoveNext()
导致此错误的原因是什么,我该如何解决?
使用此处的信息,我将地图更改为以下内容,从而解决了该问题。
from doc in docs
from text1 in ((IEnumerable<dynamic>)doc.Texts1)
from text2 in ((IEnumerable<dynamic>)doc.Texts2)
from text3 in ((IEnumerable<dynamic>)doc.Texts3)
select new
{
Text1 = text1,
Text2 = text2,
Text3 = text3
}
不幸的是,我不明白为什么会这样。仍然欢迎解释。