forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNhQueryable.cs
71 lines (62 loc) · 1.94 KB
/
NhQueryable.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using NHibernate.Engine;
using Remotion.Linq;
namespace NHibernate.Linq
{
/// <summary>
/// Interface to access the entity name of a NhQueryable instance.
/// </summary>
interface IEntityNameProvider
{
string EntityName { get; }
}
/// <summary>
/// Provides the main entry point to a LINQ query.
/// </summary>
public class NhQueryable<T> : QueryableBase<T>, IEntityNameProvider, IEnumerable<T>
{
// This constructor is called by our users, create a new IQueryExecutor.
public NhQueryable(ISessionImplementor session)
: this(session, typeof(T).FullName)
{
}
// This constructor is called by our users, create a new IQueryExecutor.
public NhQueryable(ISessionImplementor session, string entityName)
: base(QueryProviderFactory.CreateQueryProvider(session, null))
{
EntityName = entityName;
}
// This constructor is called indirectly by LINQ's query methods, just pass to base.
public NhQueryable(IQueryProvider provider, Expression expression)
: this(provider, expression, typeof(T).FullName)
{
}
// This constructor is called indirectly by LINQ's query methods, just pass to base.
public NhQueryable(IQueryProvider provider, Expression expression, string entityName)
: base(provider, expression)
{
EntityName = entityName;
}
public NhQueryable(ISessionImplementor session, object collection)
: base(QueryProviderFactory.CreateQueryProvider(session, collection))
{
EntityName = typeof(T).FullName;
}
public string EntityName { get; private set; }
public override string ToString()
{
return "NHibernate.Linq.NhQueryable`1[" + EntityName + "]";
}
IEnumerator<T> IEnumerable<T>.GetEnumerator()
{
//TODO 6.0: Cast to INhQueryProvider
return
Provider is DefaultQueryProvider nhProvider
? nhProvider.ExecuteList<T>(Expression).GetEnumerator()
: base.GetEnumerator();
}
}
}