For NHibernate 3.3.3
Think about three entity like
public class Menu{
public string Name{get;set;}
public IList<MenuAccess> MenuAccessList{get;set}
}
public class MenuAccess{
public string Name{get;set;}
public Controller MenuController{get;set;}
}
public class Controller{
public long Id{get;set;}
public string Name{get;set;}
}
consider their lazy load enabled mapping
now if in criteria query we use SetFetchMode(FetchMode.Eager) on MenuAccessList that works fine but if we create alias of MenuAccessList and add condition on that then Eagerload do not work. Throw lazy load exception if we access that later.
using(ISession session = NHSessionFactory.OpenSession()){
ICriteria criteria = session.CreateCriteria<Menu>();
criteria.CreateAlias("MenuAccessList", "ma", JoinType.InnerJoin);
criteria.SetFetchMode("ma", FetchMode.Eager);
criteria.Add(Restrictions.Eq("ma.MenuController.Id",10L));
var list = criteria.List<Menu>();
}
This query cannot load MenuAccessList from menu if we access that outside session scope.