问题描述
我是 RavendB 的新手,我在通过代码创建一些索引时遇到了问题,尤其是递归索引。
我有一个包含用户和组集合的 ravendb 实例。 User 有一个 BelongsTo 属性,它是用户直接所属组的组 ID 数组,Groups 也有一个 BelongsTo 属性,其中包含该组直接所属的组。所以:
Group: {
Id: 'Z',BelongsTo: []
}
Group: {
Id: 'X',BelongsTo: ['Z']
}
User: {
Id: 'X1',BelongsTo: ['X']
}
我想要一个索引,让我为每个用户直接或间接地获取他所属的所有组。可以有组的层次结构,唯一的规则是这个层次结构不能是循环的(我们不能让 A 组属于 B 组,而 B 组属于 A 组)。
在上面的例子中,我会让索引返回如下内容:
{
UserId: 'X1',Name: 'xpto',BelongsTo: ['X','Z']
}
我尝试使用 Recurse 创建索引,就像在以下 URL 中一样:
https://ayende.com/blog/185537-A/recursive-indexing-in-ravendb
这是我的索引的 C# 代码:
public class User_BelongedGroups : AbstractIndexCreationTask<User>
{
public User_BelongedGroups()
{
Map = users =>
from u in users
select new
{
UserId = u.Id,u.Name,BelongsTo = u.BelongsTo.Select(g => Recurse(g,gId => LoadDocument<Group>(gId).BelongsTo))
};
}
}
当我尝试创建此索引时,我收到 IndexCompilationException。当我查看 InnerException 时,我得到以下文本:
IndexCompilationException: Failed to compile index User/BelongedGroups
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using Lucene.Net.Documents;
using Raven.Client.Documents.Indexes;
using Raven.Server.Documents.Indexes.Static;
using Raven.Server.Documents.Indexes.Static.Linq;
using Raven.Server.Documents.Indexes.Static.Extensions;
namespace Raven.Server.Documents.Indexes.Static.Generated
{
public class Index_User_BelongedGroups : StaticIndexBase
{
IEnumerable Map_0(IEnumerable<dynamic> docs)
{
foreach (var u in docs)
{
yield return new
{
UserId = Id(u),Name = u.Name,BelongsTo = ((IEnumerable<dynamic>)u.BelongsTo).Select((Func<dynamic,dynamic>)(g => this.Recurse<string,string>(g,gId => (this.LoadDocument(gId,"Groups")).BelongsTo)))
}
;
}
}
public Index_User_BelongedGroups()
{
this.AddMap("Users",this.Map_0);
this.AddReferencedCollection("Users","Groups");
this.OutputFields = new System.String[] { "UserId","Name","BelongsTo" };
}
}
}
(26,111): error CS0308: The non-generic method 'AbstractStaticIndexBase.Recurse(object,Func<dynamic,dynamic>)' cannot be used with type arguments,IndexDeFinitionProperty='',ProblematicText='' at Raven.Server.Documents.Indexes.Static.IndexCompiler.CompileInternal(String originalName,String cSharpSafeName,MemberDeclarationSyntax class,IndexDeFinition deFinition) in C:\Builds\RavendB-Stable-5.1\51010\src\Raven.Server\Documents\Indexes\Static\IndexCompiler.cs:line 221
at Raven.Server.Documents.Indexes.Static.IndexCompiler.Compile(IndexDeFinition deFinition) in C:\Builds\RavendB-Stable-5.1\51010\src\Raven.Server\Documents\Indexes\Static\IndexCompiler.cs:line 149
at Raven.Server.Documents.Indexes.Static.IndexCompilationCache.GenerateIndex(IndexDeFinition deFinition,RavenConfiguration configuration,IndexType type) in C:\Builds\RavendB-Stable-5.1\51010\src\Raven.Server\Documents\Indexes\Static\IndexCompilationCache.cs:line 133
at Raven.Server.Documents.Indexes.Static.IndexCompilationCache.<>c__displayClass2_0.<GetDocumentsIndexInstance>b__1() in C:\Builds\RavendB-Stable-5.1\51010\src\Raven.Server\Documents\Indexes\Static\IndexCompilationCache.cs:line 47
at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication,Boolean useDefaultConstructor)
at System.Lazy`1.CreateValue()
at Raven.Server.Documents.Indexes.Static.IndexCompilationCache.GetDocumentsIndexInstance(IndexDeFinition deFinition,IndexType type) in C:\Builds\RavendB-Stable-5.1\51010\src\Raven.Server\Documents\Indexes\Static\IndexCompilationCache.cs:line 56
at Raven.Server.Documents.Indexes.IndexStore.ValidateStaticIndex(IndexDeFinition deFinition) in C:\Builds\RavendB-Stable-5.1\51010\src\Raven.Server\Documents\Indexes\IndexStore.cs:line 750
at Raven.Server.Documents.Indexes.IndexStore.CreateIndexInternal(IndexDeFinition deFinition,String raftRequestId,String source) in C:\Builds\RavendB-Stable-5.1\51010\src\Raven.Server\Documents\Indexes\IndexStore.cs:line 635
at Raven.Server.Documents.Handlers.Admin.AdminIndexHandler.PutInternal(Boolean validatedAsAdmin) in C:\Builds\RavendB-Stable-5.1\51010\src\Raven.Server\Documents\Handlers\Admin\AdminIndexHandler.cs:line 91
at Raven.Server.Documents.Handlers.Admin.AdminIndexHandler.Put() in C:\Builds\RavendB-Stable-5.1\51010\src\Raven.Server\Documents\Handlers\Admin\AdminIndexHandler.cs:line 33
at Raven.Server.Routing.RequestRouter.HandlePath(RequestHandlerContext reqCtx) in C:\Builds\RavendB-Stable-5.1\51010\src\Raven.Server\Routing\RequestRouter.cs:line 196
at Raven.Server.RavenServerStartup.RequestHandler(HttpContext context) in C:\Builds\RavendB-Stable-5.1\51010\src\Raven.Server\RavenServerStartup.cs:line 242
我在这里做错了什么?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)