I am trying to pull out a complete object graph using 3 queries and futures to batch the 3 calls.
Here is a cut down version of my object graph.
public class Talent
{
public virtual int Id { get; set; }
public virtual string FirstName { get; set; }
public virtual string LastName { get; set; }
public virtual string Slug { get; set; }
public virtual IList<Credit> Credits { get; set; }
public virtual IList<Show> Creations { get; set; }
}
The Talent query is able to work out how to get the Creators
However the credits don’t, I can see another SQL query being generated to fetch this data again.
Here are the queries.
//Selectes the root node
var talentQuery = session.QueryOver<Filmslave.Domain.Models.Talent>()
.Where(t => t.Slug == slug)
.Take(1)
.Future();
//Fills Talent.Creations
var creationsQuery = session.QueryOver<Filmslave.Domain.Models.Creator>()
.Fetch(c => c.Shows).Eager
.JoinQueryOver(c => c.Talent).Where(t => t.Slug == slug)
.Future();
//Fills Talent.Credits
var creditsQuery = session.QueryOver<Filmslave.Domain.Models.Credit>()
.Fetch(c => c.Role).Eager
.Fetch(c => c.Episode).Eager
.JoinQueryOver(c => c.Talent).Where(t => t.Slug == slug)
.Future();
talent = talentQuery.FirstOrDefault();
How do I get the talent to pick up it’s credits?
It should work like that, but I’ve also found eager loading relationships using the inverse to be problematic. If you invert the query it should work: