Skip to content

Commit dca135f

Browse files
committed
NH-3669 - Make Query<> methods interface members of ISession and IStatelessSession
1 parent 2e20261 commit dca135f

File tree

7 files changed

+61
-22
lines changed

7 files changed

+61
-22
lines changed

src/NHibernate/Async/ISession.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using System;
1212
using System.Data;
1313
using System.Data.Common;
14+
using System.Linq;
1415
using System.Linq.Expressions;
1516
using NHibernate.Engine;
1617
using NHibernate.Stat;

src/NHibernate/Async/IStatelessSession.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using System;
1212
using System.Data;
1313
using System.Data.Common;
14+
using System.Linq;
1415
using System.Linq.Expressions;
1516
using NHibernate.Engine;
1617

@@ -113,4 +114,4 @@ public partial interface IStatelessSession : IDisposable
113114
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
114115
Task RefreshAsync(string entityName, object entity, LockMode lockMode, CancellationToken cancellationToken = default(CancellationToken));
115116
}
116-
}
117+
}

src/NHibernate/Async/Impl/AbstractSessionImpl.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using System.Collections;
1313
using System.Collections.Generic;
1414
using System.Data.Common;
15+
using System.Linq;
1516
using NHibernate.AdoNet;
1617
using NHibernate.Cache;
1718
using NHibernate.Collection;
@@ -21,6 +22,7 @@
2122
using NHibernate.Event;
2223
using NHibernate.Exceptions;
2324
using NHibernate.Hql;
25+
using NHibernate.Linq;
2426
using NHibernate.Loader.Custom;
2527
using NHibernate.Loader.Custom.Sql;
2628
using NHibernate.Persister.Entity;

src/NHibernate/ISession.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Data;
33
using System.Data.Common;
4+
using System.Linq;
45
using System.Linq.Expressions;
56
using NHibernate.Engine;
67
using NHibernate.Stat;
@@ -962,5 +963,20 @@ public partial interface ISession : IDisposable
962963
/// <returns>The new session.</returns>
963964
[Obsolete("Please use SessionWithOptions instead. Now requires to be flushed and disposed of.")]
964965
ISession GetSession(EntityMode entityMode);
966+
967+
/// <summary>
968+
/// Creates a new Linq <see cref="IQueryable{T}"/> for the entity class.
969+
/// </summary>
970+
/// <typeparam name="T">The entity class</typeparam>
971+
/// <returns>An <see cref="IQueryable{T}"/> instance</returns>
972+
IQueryable<T> Query<T>();
973+
974+
/// <summary>
975+
/// Creates a new Linq <see cref="IQueryable{T}"/> for the entity class and with given entity name.
976+
/// </summary>
977+
/// <typeparam name="T">The type of entity to query.</typeparam>
978+
/// <param name="entityName">The entity name.</param>
979+
/// <returns>An <see cref="IQueryable{T}"/> instance</returns>
980+
IQueryable<T> Query<T>(string entityName);
965981
}
966982
}

src/NHibernate/IStatelessSession.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Data;
33
using System.Data.Common;
4+
using System.Linq;
45
using System.Linq.Expressions;
56
using NHibernate.Engine;
67

@@ -272,5 +273,20 @@ public partial interface IStatelessSession : IDisposable
272273
/// <param name="batchSize">The batch size.</param>
273274
/// <returns>The same instance of the session for methods chain.</returns>
274275
IStatelessSession SetBatchSize(int batchSize);
276+
277+
/// <summary>
278+
/// Creates a new Linq <see cref="IQueryable{T}"/> for the entity class.
279+
/// </summary>
280+
/// <typeparam name="T">The entity class</typeparam>
281+
/// <returns>An <see cref="IQueryable{T}"/> instance</returns>
282+
IQueryable<T> Query<T>();
283+
284+
/// <summary>
285+
/// Creates a new Linq <see cref="IQueryable{T}"/> for the entity class and with given entity name.
286+
/// </summary>
287+
/// <typeparam name="T">The type of entity to query.</typeparam>
288+
/// <param name="entityName">The entity name.</param>
289+
/// <returns>An <see cref="IQueryable{T}"/> instance</returns>
290+
IQueryable<T> Query<T>(string entityName);
275291
}
276-
}
292+
}

src/NHibernate/Impl/AbstractSessionImpl.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections;
33
using System.Collections.Generic;
44
using System.Data.Common;
5+
using System.Linq;
56
using NHibernate.AdoNet;
67
using NHibernate.Cache;
78
using NHibernate.Collection;
@@ -11,6 +12,7 @@
1112
using NHibernate.Event;
1213
using NHibernate.Exceptions;
1314
using NHibernate.Hql;
15+
using NHibernate.Linq;
1416
using NHibernate.Loader.Custom;
1517
using NHibernate.Loader.Custom.Sql;
1618
using NHibernate.Persister.Entity;
@@ -444,5 +446,26 @@ internal IOuterJoinLoadable GetOuterJoinLoadable(string entityName)
444446
public abstract IEnumerable<T> Enumerable<T>(IQueryExpression queryExpression, QueryParameters queryParameters);
445447

446448
public abstract int ExecuteUpdate(IQueryExpression queryExpression, QueryParameters queryParameters);
449+
450+
/// <summary>
451+
/// Creates a new Linq <see cref="IQueryable{T}"/> for the entity class.
452+
/// </summary>
453+
/// <typeparam name="T">The entity class</typeparam>
454+
/// <returns>An <see cref="IQueryable{T}"/> instance</returns>
455+
public IQueryable<T> Query<T>()
456+
{
457+
return new NhQueryable<T>(this);
458+
}
459+
460+
/// <summary>
461+
/// Creates a new Linq <see cref="IQueryable{T}"/> for the entity class and with given entity name.
462+
/// </summary>
463+
/// <typeparam name="T">The type of entity to query.</typeparam>
464+
/// <param name="entityName">The entity name.</param>
465+
/// <returns>An <see cref="IQueryable{T}"/> instance</returns>
466+
public IQueryable<T> Query<T>(string entityName)
467+
{
468+
return new NhQueryable<T>(this, entityName);
469+
}
447470
}
448471
}

src/NHibernate/Linq/LinqExtensionMethods.cs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2395,26 +2395,6 @@ async Task<List<TSource>> InternalToListAsync()
23952395

23962396
#endregion
23972397

2398-
public static IQueryable<T> Query<T>(this ISession session)
2399-
{
2400-
return new NhQueryable<T>(session.GetSessionImplementation());
2401-
}
2402-
2403-
public static IQueryable<T> Query<T>(this ISession session, string entityName)
2404-
{
2405-
return new NhQueryable<T>(session.GetSessionImplementation(), entityName);
2406-
}
2407-
2408-
public static IQueryable<T> Query<T>(this IStatelessSession session)
2409-
{
2410-
return new NhQueryable<T>(session.GetSessionImplementation());
2411-
}
2412-
2413-
public static IQueryable<T> Query<T>(this IStatelessSession session, string entityName)
2414-
{
2415-
return new NhQueryable<T>(session.GetSessionImplementation(), entityName);
2416-
}
2417-
24182398
/// <summary>
24192399
/// Wraps the query in a deferred <see cref="IFutureEnumerable{T}"/> which enumeration will trigger a batch of all pending future queries.
24202400
/// </summary>

0 commit comments

Comments
 (0)