I have the following query:
ObjectB objectBAlias = null;
ObjectC objectCAlias = null;
var query = session.QueryOver<ObjectA>();
var results = query
.JoinAlias(x => x.listOfBs, () => objectBAlias)
.JoinAlias(x => objectBAlias.ObjectC, () => objectCAlias)
.TransformUsing(new DistinctRootEntityResultTransformer())
.List<ObjectA>();
class ObjectA
{
IList<ObjectB> listOfBs;
}
class ObjectB
{
ObjectA a;
ObjectC c;
}
class ObjectC
{
int x;
}
ObjectA has a many-to-many
relationship to ObjectC with ObjectB being the joining table. ObjectA has a list of ObjectB's, and ObjectB has a proporty of ObjectC. I'm trying to eager load ObjectC but have had no success.
The only way I've gotten all the ObjectCs to eager load was by doing this:
foreach (ObjectA a in results)
{
foreach (var b in a.listOfBs)
{
NHibernateUtil.Initialize(b.c);
}
}
But this doesn't seem like something that would scale very well.