I have two classes:
public class Reference
{
public virtual string Id { get; set; }
// ...
public virtual Stamp Stamp { get; set; }
}
public class Stamp
{
public DateTime? Created { get; set; }
public User CreatedBy { get; set; }
public DateTime? LastUpdated { get; set; }
public User LastUpdatedBy { get; set; }
}
Reference.Stamp is mapped as a component (so that the "Stamp" fields appear in the Reference table) using the following fluent nhibernate mappings:
public class ReferenceMap : ClassMap<Reference>
{
public ReferenceMap()
{
Id(e => e.Id);
// ...
Component(e => e.Stamp);
}
}
public class StampMap : ComponentMap<Stamp>
{
public StampMap()
{
Map(e => e.Created);
References(e => e.CreatedBy);
Map(e => e.LastUpdated);
References(e => e.LastUpdatedBy);
}
}
I want to do an eager fetch on the "CreatedBy" and "LastUpdatedBy" fields, to avoid an N+1 when listing my "Reference" items.
I tried this:
Reference[] references = session
.Query<Reference>()
.Fetch(r => r.Stamp.CreatedBy)
.Fetch(r => r.Stamp.LastUpdatedBy)
.ToArray();
Which causes this error:
System.ArgumentException: A fetch request must be a simple member access expression of the kind o => o.Related; 'r.Stamp.CreatedBy' is too complex.
Any ideas as to how I could get my fetch working?