Skip to content

Add missing options to QueryOver #2275

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 42 additions & 5 deletions src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
using System;
using System.Collections;

using NUnit.Framework;

using NHibernate.Criterion;
using NHibernate.SqlCommand;
using NHibernate.Transform;
using NHibernate.Type;
using NHibernate.Util;

namespace NHibernate.Test.Criteria.Lambda
{
Expand Down Expand Up @@ -928,6 +923,48 @@ public void Readonly()
AssertCriteriaAreEqual(expected, actual);
}

[Test]
public void SetTimeout()
{
var expected =
CreateTestCriteria(typeof(Person))
.SetTimeout(3);

var actual =
CreateTestQueryOver<Person>()
.SetTimeout(3);

AssertCriteriaAreEqual(expected, actual);
}

[Test]
public void SetFetchSize()
{
var expected =
CreateTestCriteria(typeof(Person))
.SetFetchSize(3);

var actual =
CreateTestQueryOver<Person>()
.SetFetchSize(3);

AssertCriteriaAreEqual(expected, actual);
}

[Test]
public void SetComment()
{
var expected =
CreateTestCriteria(typeof(Person))
.SetComment("blah");

var actual =
CreateTestQueryOver<Person>()
.SetComment("blah");

AssertCriteriaAreEqual(expected, actual);
}

[Test]
public void DetachedQueryOver()
{
Expand Down
43 changes: 43 additions & 0 deletions src/NHibernate/QueryOverExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
namespace NHibernate
{
// 6.0 TODO: consider moving other criteria delegated methods to extension methods.
// It may allow better return typing for chaining, and it is slightly less code.
public static class QueryOverExtensions
{
/// <summary>
/// Set a timeout for the underlying ADO.NET query.
/// </summary>
/// <param name="queryOver">The query on which to set the timeout.</param>
/// <param name="timeout">The timeout in seconds.</param>
/// <returns><see langword="this" /> (for method chaining).</returns>
public static TQueryOver SetTimeout<TQueryOver>(this TQueryOver queryOver, int timeout) where TQueryOver: IQueryOver
{
queryOver.RootCriteria.SetTimeout(timeout);
return queryOver;
}

/// <summary>
/// Set a fetch size for the underlying ADO query.
/// </summary>
/// <param name="queryOver">The query on which to set the timeout.</param>
/// <param name="fetchSize">The fetch size.</param>
/// <returns><see langword="this" /> (for method chaining).</returns>
public static TQueryOver SetFetchSize<TQueryOver>(this TQueryOver queryOver, int fetchSize) where TQueryOver: IQueryOver
{
queryOver.RootCriteria.SetFetchSize(fetchSize);
return queryOver;
}

/// <summary>
/// Add a comment to the generated SQL.
/// </summary>
/// <param name="queryOver">The query on which to set the timeout.</param>
/// <param name="comment">A human-readable string.</param>
/// <returns><see langword="this" /> (for method chaining).</returns>
public static TQueryOver SetComment<TQueryOver>(this TQueryOver queryOver, string comment) where TQueryOver: IQueryOver
{
queryOver.RootCriteria.SetComment(comment);
return queryOver;
}
}
}