RavenDB indexing errors

2019-07-15 04:37发布

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条回答
仙女界的扛把子
2楼-- · 2019-07-15 05:40

The problem is in this line:

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

Replace this with:

              AmountPaid = g.Sum(x => (double)x.AmountPaid)
查看更多
登录 后发表回答