Correct way to use Include <TResult, TInclude>
I have two classes (they are stored in RavenDB):
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; }
}
I want to output all games with team name, date and location like this:
Poland - Greece, 2012-06-08 18:00:00 - Warsaw (POL)
I know that I could include the home team name and the team name in the game object, but I want to use RavenDB's Include functions instead.
I wrote this code:
// 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));
}
If I understood things correctly, when I load the home command and the guests command in a loop, the fetch request should not be issued to the server? But when I look in the logs I see this:
Request # 1 654: GET - 0 ms - Euro2012 - 200 - / docs / teams / 34
A document was found with key commands / 34
The first request issued to the server looks like this:
Request # 1 648: GET - 5 ms - Euro2012 - 200 - / indexes / dynamic / Games? query = & start = 0 & pageSize = 128 & aggregation = None & sort = GameTime & include = Id (/ commands)
So it looks like the commands should be "enabled"
Am I doing something wrong?
source to share
I am not familiar with the Customize () part of the request. You can do Include () yourself. Example:
http://inaspiralarray.blogspot.com/2012/03/keeping-domain-model-pure-with-ravendb.html
Include () is IRavenQueryable and also in the Raven.Client.Lightweight assembly.
source to share