diff --git a/doc/reference/modules/query_criteria.xml b/doc/reference/modules/query_criteria.xml index 7339e3b6db4..e5533524197 100644 --- a/doc/reference/modules/query_criteria.xml +++ b/doc/reference/modules/query_criteria.xml @@ -141,12 +141,35 @@ var cats = sess.CreateCriteria() .List(); foreach ( IDictionary map in cats ) { - Cat cat = (Cat) map[CriteriaUtil.RootAlias]; + Cat cat = (Cat) map[CriteriaSpecification.RootAlias]; Cat kitten = (Cat) map["kt"]; }]]> + + Note that for retrieving just kittens you can also use an entity projection. + See for more information. + - + + + Join entities without association (Entity joins or ad hoc joins) + + In criteria you have the ability to define a join to any entity, not just through a mapped association. + To achieve it, use CreateEntityAlias and CreateEntityCriteria. By example: + + + uniquelyNamedCats = sess.CreateCriteria("c") + .CreateEntityAlias( + "joinedCat", + Restrictions.And( + Restrictions.EqProperty("c.Name", "joinedCat.Name"), + Restrictions.NotEqProperty("c.Id", "joinedCat.Id")), + JoinType.LeftOuterJoin, + typeof(Cat).FullName) + .Add(Restrictions.IsNull("joinedCat.Id")) + .List();]]> + + Dynamic association fetching @@ -286,6 +309,33 @@ var results = session.CreateCriteria() .AddOrder( Order.Asc("kitName") ) .List();]]> + + You can also add an entity projection to a criteria query: + + + () + .CreateCriteria("Kittens", "kt") + .Add(Expression.Eq("Name", "F%")) + .SetProjection(Projections.Entity(typeof(Cat), "kt")) + .List();]]> + + () + .CreateCriteria("Kittens", "kt") + .Add(Expression.Eq("Name", "F%")) + .SetProjection( + Projections.RootEntity(), + Projections.Entity(typeof(Cat), "kt")) + .List(); + +foreach (var objs in cats) +{ + Cat cat = (Cat) objs[0]; + Cat kitten = (Cat) objs[1]; +}]]> + + + See for more information. + diff --git a/doc/reference/modules/query_queryover.xml b/doc/reference/modules/query_queryover.xml index 9beab8431f5..afaa2b0270f 100644 --- a/doc/reference/modules/query_queryover.xml +++ b/doc/reference/modules/query_queryover.xml @@ -213,6 +213,25 @@ IList cats = + + Join entities without association (Entity joins or ad hoc joins) + + In QueryOver you have the ability to define a join to any entity, not just through a mapped association. + To achieve it, use JoinEntityAlias and JoinEntityQueryOver. By example: + + + (() => cat) + .JoinEntityAlias( + () => joinedCat, + () => cat.Name == joinedCat.Name && cat.Id != joinedCat.Id, + JoinType.LeftOuterJoin) + .Where(() => joinedCat.Id == null) + .List();]]> + + Aliases @@ -350,6 +369,32 @@ IList catReport = + + Entities Projection + + + You can add entity projections via the AsEntity() extension. + + + () + .JoinAlias(c => c.Mate, () => mate) + .Select(c => c.AsEntity(), c => mate.Name) + .List();]]> + + + Or it can be done via the Projections.RootEntity and Projections.Entity methods + if more control over loaded entities is required. For instance, entity projections can be lazy loaded + or fetched with lazy properties: + + alias1).SetLazy(true), + Projections.Entity(() => alias2).SetFetchLazyProperties(true), + Projections.RootEntity() + )]]> + + Sub-queries