3
votes

I have created a map function in Raven that looks like this

from order in docs.WebOrderModels
 from orderLine in order.OrderLines
 where order.OrderStatus.OrderStatusId == 3
 select new{
    orderLine.Sku,
    orderLine.Quantity
 }

together with the following 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)
 }

Running this mostly work, except that I get dupliacate entries for the Sku, See the image: enter image description here

The same Sku number appears two times. When I look through the data there does not seem to be any difference other than the quantities per order object. I have tried to make two new order objects to see if happens when two order objects contains orderlines for the same sku number. But they are added together as I would expect.

I can't find any reason why the two entries are not reduced to one entry.

1

1 Answers

4
votes

You are grouping the result with:

group result by new {result.Sku, result.Quantity} into g

which will give you result entries per different (Sku & Quantity) pairs

Use

group result by result.Sku

See: https://demo.ravendb.net/demos/csharp/static-indexes/map-reduce-index#step-4