RavenDB索引错误



我刚开始使用Raven,我创建的一个索引总是无法索引任何内容。我在Raven服务器上发现了很多错误,看起来像这样:

{
    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
}

我创建的索引如下:

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)
                            };
    }
}

该索引由Raven创建(通过Raven Studio查看),看起来很好。

真正让我感到困惑的是,我使用的文档不包含任何双精度或整数,我存储的唯一数字是小数。

是什么原因导致了问题?

问题出在这一行:

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

替换为:

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

相关内容

  • 没有找到相关文章

最新更新