【发布时间】:2018-06-19 15:48:18
【问题描述】:
我正在使用最新版本的 RavenDb .Net Core 客户端和最新的服务器分发版。
我正在尝试添加此索引:
this.Map = persons => from person in persons
let company = this.LoadDocument(person.ExternalEmployeeData.CompanyId)
select new
{
CompanyName = company != null ? company.Name : string.Empty,
CompanyRegisteredName = company != null ? company.RegisteredName : string.Empty,
person.FirstName,
person.Id,
person.LastName,
person.NationalInsuranceNumber
};
this.Reduce = models => from model in models
select new
{
model.CompanyName,
model.CompanyRegisteredName,
model.FirstName,
model.Id,
model.LastName,
model.NationalInsuranceNumber
};
如果我在没有“Reduce”块的情况下添加它,它会被添加,但在查询它时,“CompanyName”和“CompanyRegisteredName”属性在输出中始终为空,尽管我可以正确过滤它们。所以我认为我需要“减少”功能。但是添加它会给我以下 NullReferenceException:
Raven.Client.Exceptions.Documents.Compilation.IndexCompilationException
HResult=0x80131500
Message=IndexCompilationException: Object reference not set to an instance of an object., IndexDefinitionProperty='Reduce', ProblematicText='results.Select(model => new {
CompanyName = model.CompanyName,
CompanyRegisteredName = model.CompanyRegisteredName,
FirstName = model.FirstName,
Id = model.Id,
LastName = model.LastName,
NationalInsuranceNumber = model.NationalInsuranceNumber
})' ---> System.NullReferenceException: Object reference not set to an instance of an object.
at Raven.Server.Documents.Indexes.Static.IndexCompiler.HandleReduce(String reduce, FieldNamesValidator fieldNamesValidator, MethodDetectorRewriter methodsDetector, String[]& groupByFields) in C:\Builds\RavenDB-Stable-4.0\src\Raven.Server\Documents\Indexes\Static\IndexCompiler.cs:line 392
--- End of inner exception stack trace ---
at Raven.Server.Documents.Indexes.Static.IndexCompiler.HandleReduce(String reduce, FieldNamesValidator fieldNamesValidator, MethodDetectorRewriter methodsDetector, String[]& groupByFields) in C:\Builds\RavenDB-Stable-4.0\src\Raven.Server\Documents\Indexes\Static\IndexCompiler.cs:line 404
at Raven.Server.Documents.Indexes.Static.IndexCompiler.CreateClass(String name, IndexDefinition definition) in C:\Builds\RavenDB-Stable-4.0\src\Raven.Server\Documents\Indexes\Static\IndexCompiler.cs:line 267
at Raven.Server.Documents.Indexes.Static.IndexCompiler.Compile(IndexDefinition definition) in C:\Builds\RavenDB-Stable-4.0\src\Raven.Server\Documents\Indexes\Static\IndexCompiler.cs:line 73
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.GetIndexInstance(IndexDefinition definition) in C:\Builds\RavenDB-Stable-4.0\src\Raven.Server\Documents\Indexes\Static\IndexCompilationCache.cs:line 46
at Raven.Server.Documents.Indexes.IndexStore.d__23.MoveNext() in C:\Builds\RavenDB-Stable-4.0\src\Raven.Server\Documents\Indexes\IndexStore.cs:line 355
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Raven.Server.Documents.Handlers.Admin.AdminIndexHandler.d__0.MoveNext() in C:\Builds\RavenDB-Stable-4.0\src\Raven.Server\Documents\Handlers\Admin\AdminIndexHandler.cs:line 50
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Raven.Server.Routing.RequestRouter.d__7.MoveNext() in C:\Builds\RavenDB-Stable-4.0\src\Raven.Server\Routing\RequestRouter.cs:line 116
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at System.Runtime.CompilerServices.ValueTaskAwaiter`1.GetResult()
at Raven.Server.RavenServerStartup.d__11.MoveNext() in C:\Builds\RavenDB-Stable-4.0\src\Raven.Server\RavenServerStartup.cs:line 161
Source=Raven.Client
StackTrace:
at Raven.Client.Exceptions.ExceptionDispatcher.d__3.MoveNext() in C:\Builds\RavenDB-Stable-4.0\src\Raven.Client\Exceptions\ExceptionDispatcher.cs:line 117
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Raven.Client.Http.RequestExecutor.d__90`1.MoveNext() in C:\Builds\RavenDB-Stable-4.0\src\Raven.Client\Http\RequestExecutor.cs:line 1014
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Raven.Client.Http.RequestExecutor.d__75`1.MoveNext() in C:\Builds\RavenDB-Stable-4.0\src\Raven.Client\Http\RequestExecutor.cs:line 806
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Raven.Client.Http.RequestExecutor.d__75`1.MoveNext() in C:\Builds\RavenDB-Stable-4.0\src\Raven.Client\Http\RequestExecutor.cs:line 806
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Raven.Client.Http.RequestExecutor.d__68`1.MoveNext() in C:\Builds\RavenDB-Stable-4.0\src\Raven.Client\Http\RequestExecutor.cs:line 417
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Raven.Client.Documents.Operations.MaintenanceOperationExecutor.d__13`1.MoveNext() in C:\Builds\RavenDB-Stable-4.0\src\Raven.Client\Documents\Operations\MaintenanceOperationExecutor.cs:line 64
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Raven.Client.Util.AsyncHelpers.RunSync(Func`1 task) in C:\Builds\RavenDB-Stable-4.0\src\Raven.Client\Util\AsyncHelpers.cs:line 79
at MyProject.DataAccess.RavenDb.ServiceCollectionExtensions.ConfigureStore(IDocumentStore store) in C:\Sviluppo\steelchihuahua\MyProject.DataAccess.RavenDb\ServiceCollectionExtensions.cs:line 65
at MyProject.DataAccess.RavenDb.ServiceCollectionExtensions.InitializeDocumentStore(IServiceCollection services, Boolean isDevelopment, Boolean isStaging, Boolean isProduction, String contentRootPath, String certificatePath, String certificatePassword, String databaseName, String databaseUrl) in C:\Sviluppo\steelchihuahua\MyProject.DataAccess.RavenDb\ServiceCollectionExtensions.cs:line 45
at MyProject.RealTimeApi.Startup.ConfigureServices(IServiceCollection services) in C:\Sviluppo\steelchihuahua\MyProject.RealTimeApi\Startup.cs:line 41
除了这种例外,我不确定我是否做错了什么,或者库中是否存在错误,或者两者兼而有之。
有人知道吗?
谢谢。
编辑:进一步试验我发现了更多问题。我一直在尝试添加一个非常简单的 map/reduce,但我遇到了一种新的(无意义的)错误,因为我已经返回了一个匿名对象。此外,如果我删除“groupby”语句(这并不是真正需要的),我会回到 NullReferenceException:
【问题讨论】:
-
了解 Map-Reduce 索引并查看示例:ravendb.net/docs/article-page/4.0/csharp/indexes/…
-
不用说我已经阅读了文档,如果我在那里找到了答案,我就不会在这里发布。
-
调用 LoadDocument 方法时缺少类型参数 ==> LoadDocument
(person.ExternalEmployeeData.CompanyId) -
这一定是由于堆栈溢出编辑器。存在类型参数,仅地图就可以正确注册。