Skip to content

Commit 99d48f5

Browse files
Add missing options to QueryOver (#2275)
Fix #2270
1 parent d8931ac commit 99d48f5

File tree

2 files changed

+85
-5
lines changed

2 files changed

+85
-5
lines changed

src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
using System;
2-
using System.Collections;
3-
42
using NUnit.Framework;
5-
63
using NHibernate.Criterion;
74
using NHibernate.SqlCommand;
85
using NHibernate.Transform;
9-
using NHibernate.Type;
10-
using NHibernate.Util;
116

127
namespace NHibernate.Test.Criteria.Lambda
138
{
@@ -928,6 +923,48 @@ public void Readonly()
928923
AssertCriteriaAreEqual(expected, actual);
929924
}
930925

926+
[Test]
927+
public void SetTimeout()
928+
{
929+
var expected =
930+
CreateTestCriteria(typeof(Person))
931+
.SetTimeout(3);
932+
933+
var actual =
934+
CreateTestQueryOver<Person>()
935+
.SetTimeout(3);
936+
937+
AssertCriteriaAreEqual(expected, actual);
938+
}
939+
940+
[Test]
941+
public void SetFetchSize()
942+
{
943+
var expected =
944+
CreateTestCriteria(typeof(Person))
945+
.SetFetchSize(3);
946+
947+
var actual =
948+
CreateTestQueryOver<Person>()
949+
.SetFetchSize(3);
950+
951+
AssertCriteriaAreEqual(expected, actual);
952+
}
953+
954+
[Test]
955+
public void SetComment()
956+
{
957+
var expected =
958+
CreateTestCriteria(typeof(Person))
959+
.SetComment("blah");
960+
961+
var actual =
962+
CreateTestQueryOver<Person>()
963+
.SetComment("blah");
964+
965+
AssertCriteriaAreEqual(expected, actual);
966+
}
967+
931968
[Test]
932969
public void DetachedQueryOver()
933970
{

src/NHibernate/QueryOverExtensions.cs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
namespace NHibernate
2+
{
3+
// 6.0 TODO: consider moving other criteria delegated methods to extension methods.
4+
// It may allow better return typing for chaining, and it is slightly less code.
5+
public static class QueryOverExtensions
6+
{
7+
/// <summary>
8+
/// Set a timeout for the underlying ADO.NET query.
9+
/// </summary>
10+
/// <param name="queryOver">The query on which to set the timeout.</param>
11+
/// <param name="timeout">The timeout in seconds.</param>
12+
/// <returns><see langword="this" /> (for method chaining).</returns>
13+
public static TQueryOver SetTimeout<TQueryOver>(this TQueryOver queryOver, int timeout) where TQueryOver: IQueryOver
14+
{
15+
queryOver.RootCriteria.SetTimeout(timeout);
16+
return queryOver;
17+
}
18+
19+
/// <summary>
20+
/// Set a fetch size for the underlying ADO query.
21+
/// </summary>
22+
/// <param name="queryOver">The query on which to set the timeout.</param>
23+
/// <param name="fetchSize">The fetch size.</param>
24+
/// <returns><see langword="this" /> (for method chaining).</returns>
25+
public static TQueryOver SetFetchSize<TQueryOver>(this TQueryOver queryOver, int fetchSize) where TQueryOver: IQueryOver
26+
{
27+
queryOver.RootCriteria.SetFetchSize(fetchSize);
28+
return queryOver;
29+
}
30+
31+
/// <summary>
32+
/// Add a comment to the generated SQL.
33+
/// </summary>
34+
/// <param name="queryOver">The query on which to set the timeout.</param>
35+
/// <param name="comment">A human-readable string.</param>
36+
/// <returns><see langword="this" /> (for method chaining).</returns>
37+
public static TQueryOver SetComment<TQueryOver>(this TQueryOver queryOver, string comment) where TQueryOver: IQueryOver
38+
{
39+
queryOver.RootCriteria.SetComment(comment);
40+
return queryOver;
41+
}
42+
}
43+
}

0 commit comments

Comments
 (0)