RavenDB indexing errors

微笑、不失礼 提交于 2019-12-12 19:19:16

问题


I'm just getting started with Raven and an index I've created keeps failing to index anything. I've found a lot of errors on the Raven server that look like this:

{
    Index: "HomeBlurb/IncludeTotalCosts",
    Error: "Cannot implicitly convert type 'double' to 'int'. An explicit conversion exists (are you missing a cast?)",
    Timestamp: "2012-01-14T15:40:40.8943226Z",
    Document: null
}

The index I've created looks like this:

public class HomeBlurb_IncludeTotalCosts : AbstractIndexCreationTask<MPDocument, HomeBlurb_IncludeTotalCosts.ReduceResult>
{
    public class ReduceResult 
    {
        public string Name { get; set; }
        public string Constituency { get; set; }
        public decimal AmountPaid { get; set; }
    }

    public HomeBlurb_IncludeTotalCosts()
    {
        Map = mps => from mp in mps
                            from expense in mp.Expenses
                            select new
                            {
                                mp.Name,
                                mp.Constituency,
                                AmountPaid = expense.AmountPaid ?? 0M
                            };

        Reduce = results => from result in results
                            group result by new { result.Name, result.Constituency } 
                            into g
                            select new
                            {
                                g.Key.Name,
                                g.Key.Constituency,
                                AmountPaid = g.Sum(x => x.AmountPaid)
                            };
    }
}

The index is created by Raven (looking at it through Raven Studio) and appears to be fine.

The thing that really throws me is that the documents I'm using do not contain any doubles or ints, the only numbers I am storing are decimals.

What might be causing the problem?


回答1:


The problem is in this line:

              AmountPaid = g.Sum(x => x.AmountPaid)

Replace this with:

              AmountPaid = g.Sum(x => (double)x.AmountPaid)


来源:https://stackoverflow.com/questions/8863283/ravendb-indexing-errors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!