English 中文(简体)
RavenDB的地图/插图扔 throw英瓦利德行动 例外
原标题:Map/reduce in RavenDB throws InvalidOperationException

我难以绘制地图/减少工作。 我 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

最佳回答

Micha, the bug is now fixed. It s within build 601. To see how you can actually implement an index like the want you asked for, take a look at this test: https://github.com/ayende/ravendb/blob/master/Raven.Tests/Bugs/MapRedue/TreeWithChildrenCount.cs

问题回答

问题完全在于地图功能必须退回匿名的类型(现在就没有这样做)。 此外,这种匿名性质必须具有与你确定的指数结果相同的特性。

我不知道如何更好地描述它,但作为一个umb的规则,可以说,地图功能必须永远以<条码”结束。 数值

我没有耳光手,而是试图用父母替代父母Id = (扼杀)null Id = -1, 看看这是否有助于。 我在试图在像我这样的指数中划出一票方面遇到了几个问题。 显然,这并不能解决问题,但可能有助于查明这一问题。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签