Orchard eager loading when using IRepository

While developing a custom module for Orchard CMS version 1.7 I created a simple 1 to many relationship as described in this article Creating 1 n and n n relations.

So I had a parent record with a property pointing to the child record:

public class ChildRecord
{
	public virtual int Id { get; set; }
	public virtual string Name { get; set; }
}
public class ParentRecord
{
	public virtual int Id { get; set; }
	public virtual ChildRecord Child{ get; set; }
	public virtual bool SelectCondition { get; set; }
}

Then, inside a controller I used the repository to get all the parent entities that satisfy a condition. Something like this:

var items = parentRepository.Table.
              Where(item => item.SelectCondition == true).ToList();

This worked fine but I wanted to eagerly load the child entity together with the parent.

The first thing I tried was to add the Aggregate attribute to the Child property inside the ChildRecord class:

public class ParentRecord
{
	public virtual int Id { get; set; }
	[Aggregate]
	public virtual ChildRecord Child{ get; set; }
	public virtual bool SelectCondition { get; set; }
}

Although the description of this attribute says:

This attribute is used to mark relationships which need to be eagerly fetched with the parent object, thus defining an aggregate in terms of DDD.

this didn’t work for me.

The solution is quite simple, but I’m posting it here just because I had some trouble finding it:

Use the Fetch extension method defined inside the class EagerFetchingExtensionMethods under the NHibernate.Linq namespace.

var items = parentRepository.Table.
              Where(item => item.SelectCondition == true).
              Fetch(c => c.ChildRecord).ToList();