我难以绘制地图/减少工作。 我 m着C#,因此,这很可能部分是由于我缺乏对Mlambda和linq的经历,无法彻底分析和理解造成错误的原因(什么是标语)。
法典完美地编纂,但执行时,它会放弃一个例外,我不理解什么部分是不正确的。
When I disable the reduce operation the error remains, so I assume it has to do with the Map part.
RavenDB 版本:RavenDB-Build-573
This is the exception: System.InvalidOperationException: Variable initializer select must have a lambda expression with an object create expression
我向拉文亚银行提供类似指数:
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
};
}
}
希望者可以为我提供一些lu。 提前感谢。
--
针对这些意见,我修改了地图/减少执行。 Raven 亚洲开发银行要求绘制地图并减少同样类型的产出,但必须诚实,这或许是正确的,因为I m输出值是实体的目标,而不是阵列中的要求。 但是,我无法以智慧达到这些价值观。
该指数在RavenDB工作室设立,但没有结果归还,因此我可以假定我的执行有误。
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
};
}
}
1. 建设601:
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
};
}
}
Error returned: [WebException: The remote server returned an error: (500) Internal Server Error.] System.Net.HttpWebRequest.GetResponse() +6111651 Raven.Client.Connection.HttpJsonRequest.ReadStringInternal(Func`1 getResponse) in c:Builds avenRaven.Client.LightweightConnectionHttpJsonRequest.cs:231
[InvalidOperationException: { "Url": "/indexes/FullTree", "Error": "System.InvalidOperationException: Could not understand query: -- line 2 col 55: invalid NewExpression -- line 2 col 91: Can t parse double .0.0 -- line 2 col 183: Can t parse double .0.0 -- line 2 col 275: Can t parse double .0.0 at Raven.Database.Linq.QueryParsingUtils.GetVariableDeclarationForLinqMethods(String query, Boolean requiresSelectNewAnonymousType) in c:Builds aven-unstableRaven.DatabaseLinqQueryParsingUtils.cs:line 122 at Raven.Database.Linq.DynamicViewCompiler.TransformMapDefinitionFromLinqMethodSyntax(String query, String& entityName) in c:Builds aven-unstableRaven.DatabaseLinqDynamicViewCompiler.cs:line 355 at Raven.Database.Linq.DynamicViewCompiler.HandleMapFunction(ConstructorDeclaration ctor, String map) in c:Builds aven-unstableRaven.DatabaseLinqDynamicViewCompiler.cs:line 132 at Raven.Database.Linq.DynamicViewCompiler.TransformQueryToClass() in c:Builds aven-unstableRaven.DatabaseLinqDynamicViewCompiler.cs:line 97 at Raven.Database.Linq.DynamicViewCompiler.GenerateInstance() in c:Builds aven-unstableRaven.DatabaseLinqDynamicViewCompiler.cs:line 489 at Raven.Database.DocumentDatabase.PutIndex(String name, IndexDefinition definition) in c:Builds aven-unstableRaven.DatabaseDocumentDatabase.cs:line 717 at Raven.Database.Server.Responders.Index.Put(IHttpContext context, String index) in c:Builds aven-unstableRaven.DatabaseServerRespondersIndex.cs:line 72 at Raven.Database.Server.Responders.Index.Respond(IHttpContext context) in c:Builds aven-unstableRaven.DatabaseServerRespondersIndex.cs:line 49 at Raven.Database.Server.HttpServer.DispatchRequest(IHttpContext ctx) in c:Builds aven-unstableRaven.DatabaseServerHttpServer.cs:line 527 at Raven.Database.Server.HttpServer.HandleActualRequest(IHttpContext ctx) in c:Builds aven-unstableRaven.DatabaseServerHttpServer.cs:line 303" }] Raven.Client.Connection.HttpJsonRequest.ReadStringInternal(Func`1 getResponse) in c:Builds avenRaven.Client.LightweightConnectionHttpJsonRequest.cs:295