使用 RavenDB 从多个字符串数组创建扇出索引的编译错误
Posted
技术标签:
【中文标题】使用 RavenDB 从多个字符串数组创建扇出索引的编译错误【英文标题】:Compilation error creating a fan-out index from multiple string arrays using RavenDB 【发布时间】:2014-12-17 15:13:26 【问题描述】:在我的 RavenDB 中,表单上有对象:
"Texts1": [
"one two",
"three four"
],
"Texts2": [
"five six",
"seven eight"
],
"Texts3": [
"nine ten",
"eleven twelve"
]
为了能够执行我想要的搜索,我正在尝试创建一个fan-out index(请忽略这样一个事实,即这不一定以良好的方式扩展):
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()
是什么导致了这个错误,我该如何解决?
【问题讨论】:
【参考方案1】:使用来自here 的信息,我将地图更改为以下解决问题的地图。
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
不幸的是,我不明白为什么会这样。仍然欢迎解释。
【讨论】:
你必须这样做,因为 C# 编译器不会处理动态 linq 查询。以上是关于使用 RavenDB 从多个字符串数组创建扇出索引的编译错误的主要内容,如果未能解决你的问题,请参考以下文章