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 NewExpressionIndex: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)),
};
}
}