This is for someone looking for nested projections and a nested join with NHibernate criteria:
public class A { public B {get;set;} public string PropertyA {get;set;} } public class B { public C {get;set;} } public class C { public string CName {get;set;} }
you cannot use "." dot as an alias + you can only access level 1 within an alias (aliasA.PropertyA)
//you have to create 3 alias for each class/instance/table DetachedCriteria joinNested3tables = DetachedCriteria.For<A>("aliasA") //level 1 alias .CreateAlias("aliasA.B", "aliasB", JoinType.InnerJoin) //level 2 alias .CreateAlias("aliasB.C", "aliasC", JoinType.InnerJoin) //level 3 alias .SetProjection(Projections.ProjectionList() .Add(Projections.Property("aliasC.CName"), "CNameProjection") //you cannot have more than 1 dot operator like below //.Add(Projections.Property("aliasB.C.CName"), "CNameProjection") );
source share