@@ -141,12 +141,35 @@ var cats = sess.CreateCriteria<Cat>()
141
141
.List<IDictionary>();
142
142
foreach ( IDictionary map in cats )
143
143
{
144
- Cat cat = (Cat) map[CriteriaUtil .RootAlias];
144
+ Cat cat = (Cat) map[CriteriaSpecification .RootAlias];
145
145
Cat kitten = (Cat) map["kt"];
146
146
}]]> </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 >
147
151
148
152
</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
+
150
173
<sect1 id =" querycriteria-dynamicfetching" >
151
174
<title >Dynamic association fetching</title >
152
175
@@ -286,6 +309,33 @@ var results = session.CreateCriteria<Cat>()
286
309
.AddOrder( Order.Asc("kitName") )
287
310
.List<object[]>();]]> </programlisting >
288
311
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 >
289
339
</sect1 >
290
340
291
341
<sect1 id =" querycriteria-detachedqueries" >
0 commit comments