我刚刚开始使用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查看)并且看起来很好。
真正引起我注意的是我正在使用的文件不包含任何双打或整数,我存储的唯一数字是小数。
可能导致问题的原因是什么?
答案 0 :(得分:0)
问题出在这一行:
AmountPaid = g.Sum(x => x.AmountPaid)
将其替换为:
AmountPaid = g.Sum(x => (double)x.AmountPaid)