- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在使用 map/reduce 操作时遇到了困难。我是 C# 的爱好者,所以可能部分是由于我缺乏 lambda 和 linq 的经验来彻底分析和理解导致错误的原因(什么是对象创建表达式)。
代码编译完美,但执行时抛出异常,我不明白哪个部分不正确。
当我禁用 reduce 操作时,错误仍然存在,所以我认为它与
map 部分。
RavenDB 版本为:RavenDB-Build-573
这是异常: System.InvalidOperationException: Variable
初始值设定项选择必须有一个带有对象的 lambda 表达式 create
表达
我为 RavenDB 提供了这样的索引:
IndexCreation.CreateIndexes(typeof(FullTree).Assembly, store);
public class FullTreeObject
{
public int Id { get; set; }
public int Count { get; set; }
public int ParentId { get; set; }
}
public class FullTree : AbstractIndexCreationTask<Entity,FullTreeObject>
{
public FullTree()
{
Map = entities => from entity in entities
let ids = new object[]
{
new { entity.Id, Count = 0,
entity.ParentId },
new { Id = entity.ParentId, Count
= 1, ParentId = (string)null}
}
from id in ids
select id;
Reduce = results => from result in results
group result by result.Id into g
let parent = g.FirstOrDefault(x =>
x.ParentId != null)
select new
{
Id = g.Key,
Count = g.Sum(x => x.Count),
ParentId = parent ==
(object)null ? (object)null : parent.ParentId
};
}
}
public class FullTree : AbstractIndexCreationTask<Entity,FullTreeObject>
{
public FullTree()
{
Map = entities => from entity in entities
let ids = new object[]
{
new { entity.Id, Count = 0, entity.ParentId },
new { Id = entity.ParentId, Count = 1, ParentId = (string)null}
}
from id in ids
select new {
entity.Id,
Count = 1,
entity.ParentId
};
Reduce = results => from result in results
group result by result.Id into g
let parent = g.FirstOrDefault(x => x.ParentId != null)
select new
{
Id = g.Key,
Count = g.Sum(x => x.Count),
ParentId = parent == (object)null ? (object)null : parent.ParentId
};
}
}
public class FullTree : AbstractIndexCreationTask<Entity, FullTree.ReduceResult>
{
public class ReduceResult
{
public int Id { get; set; }
public int Count { get; set; }
public int ParentId { get; set; }
}
public FullTree()
{
Map = entities => from entity in entities
let items = new[]
{
new { Id = (int) entity.Id, Count = (int) 0, ParentId = (int) entity.ParentId },
new { Id = (int) entity.ParentId, Count = (int) 1, ParentId = (int) 0}
}
from item in items
select new {
Id = item.Id,
Count = item.Count,
ParentId = item.ParentId
};
Reduce = results => from result in results
group result by result.Id into g
let itemWithParent = g.FirstOrDefault(x => x.ParentId != 0)
select new
{
Id = g.Key,
Count = g.Sum(x => x.Count),
ParentId = (itemWithParent == null) ? (int)0 : itemWithParent.ParentId
};
}
}
最佳答案
Micha,错误现已修复。它在构建 601 内。
要了解如何实际实现您所要求的索引,请查看此测试:https://github.com/ayende/ravendb/blob/master/Raven.Tests/Bugs/MapRedue/TreeWithChildrenCount.cs
关于c# - RavenDB 中的 Map/Reduce 抛出 InvalidOperationException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8832221/
我最近开始在 ASP.Net MVC 3 应用程序中使用 Signal R 库。我可以使用 Signal R 向客户端发送消息。但我注意到,如果我从另一个浏览器登录该应用程序,我会收到以下错误 - 异
我必须编写一个异步方法来与 Web 服务联系。这是我在 WebServiceHelper 类中的方法: public static Task SignIn(string username, stri
在 WPF 应用程序中,我有一个 BackgroundWorker 线程创建一个对象。我们称对象为 foo。 后台 worker 代码: SomeClass foo = new SomeClass()
Closed. This question needs to be more focused。它当前不接受答案。 想改善这个问题吗?更新问题,使其仅关注editing this post的一个问题。
This question already has answers here: InvalidOperationException after removing an element in an ar
我正在运行一个 .NET Core 应用程序,该应用程序正在监听 Azure 服务总线主题。当我运行该应用程序时,出现此错误: A sessionful message receiver cannot
我有一个 WPF 应用程序,其中 MainNavigationWindow 在其构造函数中注册了其他一些类的事件: SomeClass obj = new SomeClass(); obj.SomeE
我有一个 WPF 应用程序,其中 MainNavigationWindow 在其构造函数中注册了其他一些类的事件: SomeClass obj = new SomeClass(); obj.SomeE
编译程序时我没有收到任何错误,但是一旦我点击保存按钮我收到“InvalidOperationException 未处理”。 cmd.ExecuteNonQuery(); 然后突出显示,我在这上面花了一
我遇到了一个我完全不知道的问题。我收到以下错误消息: The specified Visual and the Visual do not share a common ancestor, so th
The contract type HelloIndigo.Service is not attributed with ServiceContractAttribute. In order to d
当我尝试返回要下载的文件时遇到了一些奇怪的问题,所以这是我的代码 string filePath = Path.Combine(Path1, Path2, filename); return File
我制作了一个程序,我想在其中手动更新数据 GridView 。- 我有一种方法可以通过清除 DGV 然后重新插入数据来刷新它。-使用设计器,我为 DGV 的 CellEndEdit 制作了一个事件处理
情况示意图 我开发了一个系统,可以将许多 Material (代码Matetiaal)添加到广告(代码Zoeker)。这种关系是多对多的。在这里你得到了我的类的结构。 +---------------
我有以下代码来构建从 SQL Server 中提取的高级数据结构,然后当该数据的检索完成时,我更新 UI。使用的代码是 private void BuildSelectedTreeViewSectio
我正在尝试使用表达式树,因为根据描述,这似乎是最正确(性能最好、可配置)的方法。 我希望能够编写一个语句,从 existingItems 集合中获取与 incomingItem 的 propertyN
问题 我有一个 MVVM 应用程序,它使用 Caliburn.Micro 作为 MVVM 框架,并使用 MEF 进行“依赖注入(inject)”(在引号中我知道它不是严格意义上的 DI 容器)。根据
我正在 try catch 声明变量时有时会发生的 InvalidOperationException。但是,以下代码不起作用。可能是因为我真的不知道你是如何捕捉到异常的。 public overri
在我尝试了很多很多解决方案之后,我无法以任何方式解决这个问题,所以我开始相信这个问题没有解决方案。 我有一个包含复杂属性的对象。例如:List .我正在工作线程上运行此类中的一个方法,以保持 GUI
情况: 我依靠默认的关联处理程序为各种文件类型(图片、Word 文档等)生成进程。这意味着我只将特定文件名指定为 StartInfo.FileName,并且在该文件名之前没有实际的可执行文件。同时我指
我是一名优秀的程序员,十分优秀!