3

Have a piece of code like:

public class Idea 
{

    (...)
     public IList<IdeaSupporter> Supporters { get; set; }

}

public class IdeaSupporter
{
     (...)
   public int Tokens { get; set; }
}

Try to order ideas by supporters tokens. I know i must use map-reduce but i quite new at it. Anyone knows how should using map-reduce in that case correcty looks?

Kamil Będkowski
  • 1,092
  • 4
  • 16
  • 36

1 Answers1

0

The index should look like:

from idea in docs.Ideas
select new 
{
  SumOfSupportersTokens = idea.Supporters.Sum(x=>x.Tokens)
}

Note that this isn't a map/reduce index, it is a simple map index that outputs the sum. You can then order on that.

Ayende Rahien
  • 22,925
  • 1
  • 36
  • 41
  • Thanks! Have two short questions yet: 1)I should add that index on document level ,not in code,right? 2) how can iuse that index in code: `list.OrderByDescending(????)` – Kamil Będkowski Dec 21 '11 at 09:15
  • That index cant be saved-error has occured: `error CS1977: Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type` Any idea how should it looks like? – Kamil Będkowski Dec 21 '11 at 10:51