我正在使用最新版本的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”属性在输出中始终为null,尽管我可以正确地过滤它们。所以我认为我需要“减少”功能。但添加它会给我以下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:答案 0 :(得分:1)
事实证明,在Map定义之后,我所需要的只是:
this.StoreAllFields(FieldStorage.Yes);
这会保留索引中的数据。然后我必须显式地设计我的查询,即使我已经使用索引输出作为我的IQueryable的类型T:
var items = await pagedQuery.ProjectInto<TIndexOutput>()
但是,应该解决服务器报告的奇怪错误消息。 A&#34; NullReferenceException&#34;表示一个不应该是的场景,RavenDB单元测试不包括这个场景。当我这样做时,我需要输出匿名类型的消息也是非常误导的。
答案 1 :(得分:0)
Map-Reduce索引需要 no 。
Map-Reduce用于执行数据聚合。
只需查看 company.Name (而不仅仅是 公司 ),如下所示:
this.Map = persons => from person in persons
let company = this.LoadDocument<T>(person.ExternalEmployeeData.CompanyId)
select new
{
// check on company.Name
CompanyName = company.Name != null ? company.Name : string.Empty,
CompanyRegisteredName = company.Name != null ? company.RegisteredName : string.Empty,
person.FirstName,
person.Id,
person.LastName,
person.NationalInsuranceNumber
};