我有兩個類(他們在RavenDB堅持):使用正確的方法包括<TResult,TInclude>
public class Game
{
public int Id { get; set; }
public int HomeTeamId { get; set; }
public int AwayTeamId { get; set; }
public DateTime GameTime { get; set; }
public string Location { get; set; }
public int HomeTeamScore { get; set; }
public int AwayTeamScore { get; set; }
}
public class Team
{
public int Id { get; set; }
public string Name { get; set; }
public int? PositionInGroup { get; set; }
public int? PositionInPlayOffs { get; set; }
public string Group { get; set; }
}
我要輸出所有的球隊名稱,日期和地點這樣的遊戲:
波蘭 - 希臘,2012-06-08 18:00:00 - 華沙(POL)
我知道我可以在遊戲中的實體包括主隊名和客隊的名字,但不是做t我想要使用Include RavenDB包含的功能。
我寫了這個代碼:
// Print the schedule
var games = session
.Query<Game>()
.Customize(c => c.Include<Game, Team>(i => i.Id))
.OrderBy(x => x.GameTime)
.ToList();
foreach (var g in games)
{
var homeTeam = session.Load<Team>(g.HomeTeamId);
var awayTeam = session.Load<Team>(g.AwayTeamId);
Console.WriteLine(
string.Format("{0} - {1}, {2} - {3}",
homeTeam.Name,
awayTeam.Name,
g.GameTime,
g.Location));
}
如果我理解正確的事情,當我加載主隊和客隊在循環GET請求不應該向服務器發出?但是,當我看到在日誌中我可以看到這一點:
請求#1 654:GET - 0毫秒 - EURO2012 - 200 - /文檔/團隊/ 34
文檔與關鍵 '的球隊/ 34'發現
向服務器發出的第一個請求是這樣的:
請求#1 648:GET - 5毫秒 - EURO2012 - 200 - /索引/動態/遊戲查詢= &啓動= 0 &的pageSize = 128 &聚集=無&排序= GameTime &包括= ID(團隊/)
所以它看起來像支球隊應該被 「列入」
難道我做錯了什麼?
我不熟悉的自定義()一塊查詢。你可以自己做Include()。這有助於:http://inaspiralarray.blogspot.com/2012/03/keeping-domain-model-pure-with-ravendb.html? – 2012-04-09 13:23:41
我沒有在查詢中獲得包含方法,請參閱任何規範。部件?我將RavenDB客戶端添加到我的項目中 – Felix 2012-04-09 13:27:15
Include()是一個IRavenQueryable,它位於Raven.Client.Lightweight程序集中。 – 2012-04-09 13:36:13