@@ -141,12 +141,35 @@ var cats = sess.CreateCriteria<Cat>()
141141 .List<IDictionary>();
142142foreach ( IDictionary map in cats )
143143{
144- Cat cat = (Cat) map[CriteriaUtil .RootAlias];
144+ Cat cat = (Cat) map[CriteriaSpecification .RootAlias];
145145 Cat kitten = (Cat) map["kt"];
146146}]]> </programlisting >
147+ <para >
148+ Note that for retrieving just kittens you can also use entity projection.
149+ See <xref linkend =" querycriteria-projection" /> for more information.
150+ </para >
147151
148152 </sect1 >
149-
153+
154+ <sect1 id =" querycriteria_entityjoin" >
155+ <title >Join entities without association (Entity joins or ad hoc joins)</title >
156+ <para >
157+ In criteria you have the ability to define a join to any entity, not just a mapped association.
158+ To achieve it use <literal >CreateEntityAlias</literal > and <literal >CreateEntityCriteria</literal >. By example:
159+ </para >
160+
161+ <programlisting ><![CDATA[ IList<Cat> uniquelyNamedCats = sess.CreateCriteria<Cat>("c")
162+ .CreateEntityAlias(
163+ "joinedCat",
164+ Restrictions.And(
165+ Restrictions.EqProperty("c.Name", "joinedCat.Name"),
166+ Restrictions.NotEqProperty("c.Id", "joinedCat.Id")),
167+ JoinType.LeftOuterJoin,
168+ typeof(Cat).FullName)
169+ .Add(Restrictions.IsNull("joinedCat.Id"))
170+ .List();]]> </programlisting >
171+ </sect1 >
172+
150173 <sect1 id =" querycriteria-dynamicfetching" >
151174 <title >Dynamic association fetching</title >
152175
@@ -286,6 +309,33 @@ var results = session.CreateCriteria<Cat>()
286309 .AddOrder( Order.Asc("kitName") )
287310 .List<object[]>();]]> </programlisting >
288311
312+ <para >
313+ You can also add entity projection to criteria:
314+ </para >
315+
316+ <programlisting ><![CDATA[ var kittens = sess.CreateCriteria<Cat>()
317+ .CreateCriteria("Kittens", "kt")
318+ .Add(Expression.Eq("Name", "F%"))
319+ .SetProjection(Projections.Entity(typeof(Cat), "kt"))
320+ .List();]]> </programlisting >
321+
322+ <programlisting ><![CDATA[ var cats = sess.CreateCriteria<Cat>()
323+ .CreateCriteria("Kittens", "kt")
324+ .Add(Expression.Eq("Name", "F%"))
325+ .SetProjection(
326+ Projections.RootEntity(),
327+ Projections.Entity(typeof(Cat), "kt"))
328+ .List<object[]>();
329+
330+ foreach (var objs in cats)
331+ {
332+ Cat cat = (Cat) objs[0];
333+ Cat kitten = (Cat) objs[1];
334+ }]]> </programlisting >
335+
336+ <para >
337+ See <xref linkend =" queryqueryover-projectionentities" /> for more information.
338+ </para >
289339 </sect1 >
290340
291341 <sect1 id =" querycriteria-detachedqueries" >
0 commit comments