Re: [RavenDB] Generic dictionary in static index

61 views
Skip to first unread message

Oren Eini (Ayende Rahien)

unread,
Jun 27, 2012, 4:05:14 AM6/27/12
to rav...@googlegroups.com
Thanks, fixed in the next build, would be available soon

On Tue, Jun 26, 2012 at 12:28 AM, Jonas Jämtberg <jo...@jamtberg.se> wrote:
I'm trying to learn RavenDB by making a program for keeping track of golf rounds, but have run into a problem when trying to create a static index for calculating the median number of strokes on a hole.
The everything works great without the Distribution-property.
 
Error-message: 
System.InvalidOperationException: Could not understand query:

-- line 3 col 319: invalid NewExpression
 
Index:

public class PlayerScore_Distribution :
    AbstractIndexCreationTask<Round, PlayerScore_Distribution.ScoreDistribution>
{
    public class ScoreDistribution
    {
        public string PlayerName { get; set; }

        public string CourseId { get; set; }

        public int HoleNumber { get; set; }

        public Dictionary<int,int> Distribution { get; set; }
    }

    public PlayerScore_Distribution()
    {
        this.Map = rounds =>
            from round in rounds
            from playerRound in round.PlayerRounds
            from score in playerRound.Scores
            select new
            {
                round.CourseId,
                playerRound.PlayerName,
                score.HoleNumber,
                Distribution = new Dictionary<int,int> { { score.Strokes, 1} },
            };

        this.Reduce = results =>
            from result in results
            group result by new { result.CourseId, result.HoleNumber, result.PlayerName } into g
            select new
            {
                g.Key.CourseId,
                g.Key.HoleNumber,
                g.Key.PlayerName,
                Distribution = g
                    .SelectMany(x => x.Distribution)
                    .GroupBy(x => x.Key)
                    .ToDictionary(x => x.Key, x => x.Sum(y => y.Value)),
            };
    }
}


Jonas Jämtberg

unread,
Jun 27, 2012, 9:27:39 AM6/27/12
to rav...@googlegroups.com
Awesome, thanks!
Reply all
Reply to author
Forward
0 new messages