我在 Raven 中创建了一个 map 函数,看起来像这样
from order in docs.WebOrderModels
from orderLine in order.OrderLines
where order.OrderStatus.OrderStatusId == 3
select new{
orderLine.Sku,
orderLine.Quantity
}
连同下面的reduce
from result in results
group result by new {result.Sku, result.Quantity} into g
select new{
Sku = g.Key.Sku,
Quantity = g.Sum(x => x.Quantity)
}
运行这主要是工作,除了我得到 Sku 的重复条目,参见图像:
同一个Sku编号出现两次。 当我查看数据时,除了每个订单对象的数量外,似乎没有任何差异。 我试图制作两个新的订单对象,看看当两个订单对象包含相同 sku 编号的订单行时是否会发生。但正如我所料,它们是加在一起的。
我找不到任何原因为什么两个条目没有减少到一个条目。
最佳答案
您将结果分组为:
group result by new {result.Sku, result.Quantity} into g
这将为您提供每个不同(Sku 和数量)对的结果条目
使用
group result by result.Sku
参见: https://demo.ravendb.net/demos/csharp/static-indexes/map-reduce-index#step-4
关于mapreduce - RavenDB 映射减少,减少中的重复条目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63188264/