public class AggregateAmountsPerItem : AbstractIndexCreationTask { public override IndexDefinition CreateIndexDefinition() { return new IndexDefinition<Order, ItemAggregate> { Map = orders => from order in orders from item in order.Items select new {item.Name, item.Amount}, Reduce = items => from item in items group item by item.Name into i let amount = i.Max(x => x.Amount) sortby amount descending select new {Name = i.Key, Amount = i.Sum(x => x.Amount)} }.ToIndexDefinition(DocumentStore.Conventions); } }
Hi Ayende,Got it. Thanks for your answer.BTW, it seems we could not do Max on "long" type or "DateTime".E.g.In below code, If the "Amount" type is "long" or "DateTime", would it work?
public class AggregateAmountsPerItem : AbstractIndexCreationTask { public override IndexDefinition CreateIndexDefinition() { return new IndexDefinition<Order, ItemAggregate> { Map = orders => from order in orders from item in order.Items select new {item.Name, item.Amount}, Reduce = items => from item in items group item by item.Name into i let amount = i.Max(x => x.Amount)
select new {Name = i.Key, Amount = amount}
}.ToIndexDefinition(DocumentStore.Conventions); } }
--
Regards,
Steven Zhang
Error On:TagAggregateIndexError: Cannot convert null to 'int' because it is a non-nullable value type
TimeStamp: Thu Jan 13 2011 22:26:12.57Document: null