Is there a way to load an NHibernate entity, with a clause on a child collection? I have a scenario where I log changes in "Operations" i.e. one operation can contain changes to multiple entities. When I want to load the log for a specific entity, I load all Operations with any Changes made to that entity. Loading these Operations cause all changes to be loaded - I only want the relevant changes to be loaded.
Classes:
public class Operation{
public virtual DateTime TimeStamp { get; set; }
public virtual IList<Change> Changes { get; private set; }
}
public class Change{
public virtual string ChangeText { get; set; }
public virtual int EntityId { get; set; }
}
Getting the operations for a given entity
Session.QueryOver<Operation>().Where(o => o.Changes.Any(c => c.EntityId == entityId));