2
votes

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
Which build are you using? I just tried your index in a small demo using 573 and it worked without any problems, didn't see any indexing errors. - Daniel Lang
I removed and replaced all the project references, rebuilt the client, restarted the server and reimported the data, now it all seems fine. - ilivewithian

1 Answers

0
votes

The problem is in this line:

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

Replace this with:

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