1
繼this questionRavenDB:如何創建MapReduce的索引返回兒童的篩選對象列表
我有以下的文檔結構:
Game
- Id
- Teams
- Team 1
- list of players
- Team 2
- list of players
- Events
- Event 1
- type: Pass
- teamId
- PlayerId
- Event 2
- type: Goal
- teamId
- PlayerId
如何建立,讓我所有的事件的索引對於給定遊戲的玩家?
這是我得到多遠,RavenDB說它不能理解我的查詢?
public class Games_PlayerEvents : AbstractIndexCreationTask<Game, Games_PlayerEvents.ReduceResult>
{
public class ReduceResult
{
public string PlayerId { get; set; }
public IEnumerable<GameEvent> Events { get; set; }
}
public Games_PlayerEvents()
{
Map = games => from game in games
select new
{
PlayerId = "",
Events = game.Events
};
Reduce = results => from result in results
from @event in result.Events
group @event by @event.PlayerId into playerEvents
select new
{
PlayerId = playerEvents.Key,
Events = playerEvents.Select(g => g)
};
}
}
公平點。然而,玩家不是完整的實體,而只是一個名字和一個ID,所以我不認爲他們應該生活在Game對象之外。我原本以爲將事件分成GameEvents對象是因爲它們在整個遊戲中經常更新,但我仍然會遇到類似的問題。你認爲我真的需要分開模型來查詢它嗎? – marto 2012-02-27 22:33:48
不,你不需要索引就可以查詢它,所以在單獨的文檔中建模只是一個建議。正如我上面所說的,只需加載文檔並執行正常的linq查詢即可。 – 2012-02-27 23:55:38