Skip to content

Commit 59a532b

Browse files
committed
Replace IQueryNextVer with an extension method
1 parent 0549bce commit 59a532b

File tree

4 files changed

+22
-34
lines changed

4 files changed

+22
-34
lines changed

src/NHibernate/Async/Impl/AbstractQueryImpl.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
namespace NHibernate.Impl
2828
{
29-
public abstract partial class AbstractQueryImpl : IQuery, IQueryNextVer
29+
public abstract partial class AbstractQueryImpl : IQuery
3030
{
3131

3232
#region Execution methods

src/NHibernate/IQuery.cs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,36 @@
33
using NHibernate.Transform;
44
using NHibernate.Type;
55
using System.Collections.Generic;
6+
using NHibernate.Impl;
67

78
namespace NHibernate
89
{
9-
// 6.0 TODO add to IQuery
10-
internal interface IQueryNextVer : IQuery
10+
// 6.0 TODO remove
11+
internal static class QueryExtensions
1112
{
1213
/// <summary>
1314
/// Bind a value to a named query parameter
1415
/// </summary>
16+
/// <param name="query">The query</param>
1517
/// <param name="name">The name of the parameter</param>
1618
/// <param name="val">The possibly null parameter value</param>
1719
/// <param name="type">The NHibernate <see cref="IType"/>.</param>
1820
/// <param name="preferMetadataType">If true supplied type is used only if parameter metadata is missing</param>
19-
IQuery SetParameter(string name, object val, IType type, bool preferMetadataType);
21+
public static void SetParameter(this IQuery query, string name, object val, IType type, bool preferMetadataType)
22+
{
23+
if (query is AbstractQueryImpl impl)
24+
{
25+
impl.SetParameter(name, val, type, preferMetadataType);
26+
}
27+
else
28+
{
29+
//Let HQL try to process guessed types (hql doesn't support type guessing for NULL)
30+
if (type != null && (preferMetadataType == false || val == null))
31+
query.SetParameter(name, val, type);
32+
else
33+
query.SetParameter(name, val);
34+
}
35+
}
2036
}
2137

2238
/// <summary>
@@ -677,4 +693,5 @@ public partial interface IQuery
677693
/// <returns></returns>
678694
IFutureValue<T> FutureValue<T>();
679695
}
696+
680697
}

src/NHibernate/Impl/AbstractQueryImpl.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace NHibernate.Impl
1919
/// <summary>
2020
/// Abstract implementation of the IQuery interface.
2121
/// </summary>
22-
public abstract partial class AbstractQueryImpl : IQuery, IQueryNextVer
22+
public abstract partial class AbstractQueryImpl : IQuery
2323
{
2424
private readonly string queryString;
2525
protected readonly ISessionImplementor session;

src/NHibernate/Linq/DefaultQueryProvider.cs

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -253,36 +253,7 @@ protected virtual object ExecuteQuery(NhLinqExpression nhLinqExpression, IQuery
253253
#pragma warning restore 618
254254
}
255255

256-
//TODO 6.0: Remove
257256
private static void SetParameters(IQuery query, IDictionary<string, NamedParameter> parameters)
258-
{
259-
if (query is IQueryNextVer impl)
260-
{
261-
SetParameters(impl, parameters);
262-
return;
263-
}
264-
foreach (var parameterName in query.NamedParameters)
265-
{
266-
// The parameter type will be taken from the parameter metadata
267-
var parameter = parameters[parameterName];
268-
if (parameter.IsCollection)
269-
{
270-
query.SetParameterList(parameter.Name, (IEnumerable) parameter.Value);
271-
}
272-
else
273-
{
274-
//Let HQL try to process guessed types (hql doesn't support type guessing for NULL)
275-
if (parameter.Type != null && (parameter.IsGuessedType == false || parameter.Value == null))
276-
query.SetParameter(parameter.Name, parameter.Value, parameter.Type);
277-
else
278-
query.SetParameter(parameter.Name, parameter.Value);
279-
}
280-
}
281-
}
282-
283-
//TODO 6.0: Replace with
284-
//private static void SetParameters(IQuery query, IDictionary<string, NamedParameter> parameters)
285-
private static void SetParameters(IQueryNextVer query, IDictionary<string, NamedParameter> parameters)
286257
{
287258
foreach (var parameterName in query.NamedParameters)
288259
{

0 commit comments

Comments
 (0)