Skip to content

Commit ee91396

Browse files
bahusoidfredericDelaporte
authored andcommitted
Full control of entities fetching in Criteria (#1599)
* Obsolete old SetFetchMode/Fetch
1 parent 13e9e19 commit ee91396

File tree

90 files changed

+2377
-246
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+2377
-246
lines changed

doc/reference/modules/performance.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -235,20 +235,20 @@ int accessLevel = permissions["accounts"]; // Error!]]></programlisting>
235235
<literal>left join fetch</literal> in HQL. This tells NHibernate to fetch
236236
the association eagerly in the first select, using an outer join. In the
237237
<literal>ICriteria</literal> query API, you would use
238-
<literal>SetFetchMode(FetchMode.Join)</literal>.
238+
<literal>Fetch()</literal>.
239239
</para>
240240

241241
<para>
242242
If you ever feel like you wish you could change the fetching strategy used by
243243
<literal>Get()</literal> or <literal>Load()</literal>, simply use a
244244
<literal>ICriteria</literal> query, for example:
245245
</para>
246-
246+
247247
<programlisting><![CDATA[User user = session.CreateCriteria(typeof(User))
248-
.SetFetchMode("Permissions", FetchMode.Join)
248+
.Fetch(SelectMode.Fetch, "Permissions")
249249
.Add( Expression.Eq("Id", userId) )
250250
.UniqueResult<User>();]]></programlisting>
251-
251+
252252
<para>
253253
(This is NHibernate's equivalent of what some <emphasis>ORM</emphasis> solutions call a "fetch plan".)
254254
</para>
@@ -475,7 +475,7 @@ using(var iter = session
475475
<literal>NHibernateUtil.Initialize()</literal> for each collection that will
476476
be needed in the web tier (this call must occur before the session is closed)
477477
or retrieves the collection eagerly using a NHibernate query with a
478-
<literal>FETCH</literal> clause or a <literal>FetchMode.Join</literal> in
478+
<literal>FETCH</literal> clause or a <literal>SelectMode.Fetch</literal> in
479479
<literal>ICriteria</literal>. This is usually easier if you adopt the
480480
<emphasis>Command</emphasis> pattern instead of a <emphasis>Session Facade</emphasis>.
481481
</para>

doc/reference/modules/query_criteria.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,13 @@ foreach ( IDictionary map in cats )
175175

176176
<para>
177177
You may specify association fetching semantics at runtime using
178-
<literal>SetFetchMode()</literal>.
178+
<literal>Fetch()</literal>.
179179
</para>
180180

181181
<programlisting><![CDATA[var cats = sess.CreateCriteria<Cat>()
182182
.Add( Expression.Like("Name", "Fritz%") )
183-
.SetFetchMode("Mate", FetchMode.Eager)
184-
.SetFetchMode("Kittens", FetchMode.Eager)
183+
.Fetch(SelectMode.Fetch, "Mate")
184+
.Fetch(SelectMode.Fetch, "Kittens")
185185
.List<Cat>();]]></programlisting>
186186

187187
<para>

src/NHibernate.Test/Async/Criteria/CriteriaQueryTest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,7 @@ public async Task ProjectionsTestAsync()
10891089

10901090
object g = await (s.CreateCriteria(typeof(Student))
10911091
.Add(Expression.IdEq(667L))
1092-
.SetFetchMode("enrolments", FetchMode.Join)
1092+
.Fetch("enrolments")
10931093
//.setFetchMode("enrolments.course", FetchMode.JOIN) //TODO: would love to make that work...
10941094
.UniqueResultAsync());
10951095
Assert.AreSame(gavin, g);
@@ -1279,7 +1279,7 @@ public async Task CloningProjectionsTestAsync()
12791279

12801280
ICriteria criteriaToClone6 = s.CreateCriteria(typeof(Student))
12811281
.Add(Expression.IdEq(667L))
1282-
.SetFetchMode("enrolments", FetchMode.Join);
1282+
.Fetch("enrolments");
12831283
object g = await (CriteriaTransformer.Clone(criteriaToClone6)
12841284
.UniqueResultAsync());
12851285
Assert.AreSame(gavin, g);
@@ -2426,7 +2426,7 @@ public async Task SubcriteriaJoinTypesAsync()
24262426
}
24272427

24282428
result = await (session.CreateCriteria(typeof(Student))
2429-
.SetFetchMode("PreferredCourse", FetchMode.Join)
2429+
.Fetch("PreferredCourse")
24302430
.CreateCriteria("PreferredCourse", JoinType.LeftOuterJoin)
24312431
.AddOrder(Order.Asc("CourseCode"))
24322432
.ListAsync());
@@ -2436,7 +2436,7 @@ public async Task SubcriteriaJoinTypesAsync()
24362436
Assert.IsNotNull(result[2]);
24372437

24382438
result = await (session.CreateCriteria(typeof(Student))
2439-
.SetFetchMode("PreferredCourse", FetchMode.Join)
2439+
.Fetch("PreferredCourse")
24402440
.CreateAlias("PreferredCourse", "pc", JoinType.LeftOuterJoin)
24412441
.AddOrder(Order.Asc("pc.CourseCode"))
24422442
.ListAsync());

src/NHibernate.Test/Async/Criteria/Lambda/IntegrationFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ public async Task OverrideEagerJoinAsync()
290290
{
291291
var persons =
292292
await (s.QueryOver<Parent>()
293-
.Fetch(p => p.Children).Lazy
293+
.Fetch(SelectMode.Skip, p => p.Children)
294294
.ListAsync());
295295

296296
Assert.That(persons.Count, Is.EqualTo(1));

0 commit comments

Comments
 (0)