Skip to content

Commit 1e0d618

Browse files
committed
Update Remotion.Linq to 2.1
1 parent a4cbae9 commit 1e0d618

File tree

78 files changed

+1050
-654
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+1050
-654
lines changed

src/NHibernate.Test/Linq/CustomQueryModelRewriterTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,16 @@ public QueryModelVisitorBase CreateVisitor(VisitorParameters parameters)
4040
}
4141
}
4242

43-
public class CustomVisitor : QueryModelVisitorBase
43+
public class CustomVisitor : NhQueryModelVisitorBase
4444
{
4545
public override void VisitWhereClause(WhereClause whereClause, QueryModel queryModel, int index)
4646
{
47-
whereClause.TransformExpressions(new Visitor().VisitExpression);
47+
whereClause.TransformExpressions(new Visitor().Visit);
4848
}
4949

50-
private class Visitor : ExpressionTreeVisitor
50+
private class Visitor : RelinqExpressionVisitor
5151
{
52-
protected override Expression VisitBinaryExpression(BinaryExpression expression)
52+
protected override Expression VisitBinary(BinaryExpression expression)
5353
{
5454
if (
5555
expression.NodeType == ExpressionType.Equal ||
@@ -82,7 +82,7 @@ protected override Expression VisitBinaryExpression(BinaryExpression expression)
8282
}
8383
}
8484

85-
return base.VisitBinaryExpression(expression);
85+
return base.VisitBinary(expression);
8686
}
8787
}
8888
}

src/NHibernate.Test/NHibernate.Test.csproj

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,14 @@
8383
<HintPath>..\packages\NUnit.3.6.0\lib\net45\nunit.framework.dll</HintPath>
8484
<Private>True</Private>
8585
</Reference>
86+
<Reference Include="Remotion.Linq, Version=2.1.0.0, Culture=neutral, PublicKeyToken=fee00910d6e5f53b, processorArchitecture=MSIL">
87+
<HintPath>..\packages\Remotion.Linq.2.1.2\lib\net45\Remotion.Linq.dll</HintPath>
88+
</Reference>
89+
<Reference Include="Remotion.Linq.EagerFetching, Version=2.1.0.0, Culture=neutral, PublicKeyToken=fee00910d6e5f53b, processorArchitecture=MSIL">
90+
<HintPath>..\packages\Remotion.Linq.EagerFetching.2.1.0\lib\net45\Remotion.Linq.EagerFetching.dll</HintPath>
91+
</Reference>
8692
<Reference Include="System" />
93+
<Reference Include="System.ComponentModel.Composition" />
8794
<Reference Include="System.configuration" />
8895
<Reference Include="System.Core">
8996
<RequiredTargetFramework>3.5</RequiredTargetFramework>
@@ -103,9 +110,6 @@
103110
<Reference Include="System.Xml.Linq">
104111
<RequiredTargetFramework>3.5</RequiredTargetFramework>
105112
</Reference>
106-
<Reference Include="Remotion.Linq, Version=1.15.15.0, Culture=neutral, PublicKeyToken=fee00910d6e5f53b, processorArchitecture=MSIL">
107-
<HintPath>..\packages\Remotion.Linq.1.15.15.0\lib\portable-net45+wp80+wpa81+win\Remotion.Linq.dll</HintPath>
108-
</Reference>
109113
</ItemGroup>
110114
<ItemGroup>
111115
<Compile Include="..\SharedAssemblyInfo.cs">

src/NHibernate.Test/packages.config

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
<package id="Iesi.Collections" version="4.0.1.4000" targetFramework="net461" />
55
<package id="log4net" version="2.0.7" targetFramework="net461" />
66
<package id="NUnit" version="3.6.0" targetFramework="net461" />
7-
<package id="Remotion.Linq" version="1.15.15.0" targetFramework="net461" />
7+
<package id="Remotion.Linq" version="2.1.2" targetFramework="net461" />
8+
<package id="Remotion.Linq.EagerFetching" version="2.1.0" targetFramework="net461" />
89
<package id="System.Linq.Dynamic" version="1.0.7" targetFramework="net461" />
910
<!-- System.Threading.Tasks.Extensions is required for dynamically loaded Npgsql.dll (Postgresql driver) -->
1011
<package id="System.Threading.Tasks.Extensions" version="4.3.0" targetFramework="net461" />
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
using Remotion.Linq;
3+
4+
namespace NHibernate.Linq.Clauses
5+
{
6+
public abstract class NhClauseBase
7+
{
8+
/// <summary>
9+
/// Accepts the specified visitor.
10+
/// </summary>
11+
/// <param name="visitor">The visitor to accept.</param>
12+
/// <param name="queryModel">The query model in whose context this clause is visited.</param>
13+
/// <param name="index">
14+
/// The index of this clause in the <paramref name="queryModel" />'s
15+
/// <see cref="P:Remotion.Linq.QueryModel.BodyClauses" /> collection.
16+
/// </param>
17+
public void Accept(IQueryModelVisitor visitor, QueryModel queryModel, int index)
18+
{
19+
if (visitor == null) throw new ArgumentNullException(nameof(visitor));
20+
if (queryModel == null) throw new ArgumentNullException(nameof(queryModel));
21+
if (!(visitor is INhQueryModelVisitor nhVisitor))
22+
throw new ArgumentException("Expect visitor to implement INhQueryModelVisitor", nameof(visitor));
23+
24+
Accept(nhVisitor, queryModel, index);
25+
}
26+
27+
protected abstract void Accept(INhQueryModelVisitor visitor, QueryModel queryModel, int index);
28+
}
29+
}
Lines changed: 66 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,78 @@
1-
using Remotion.Linq.Clauses;
2-
using Remotion.Linq.Clauses.ExpressionTreeVisitors;
1+
using System;
32
using System.Linq.Expressions;
3+
using Remotion.Linq;
4+
using Remotion.Linq.Clauses;
45

56
namespace NHibernate.Linq.Clauses
67
{
7-
public class NhHavingClause : WhereClause
8+
public class NhHavingClause : NhClauseBase, IBodyClause
89
{
9-
public NhHavingClause(Expression predicate)
10-
: base(predicate)
10+
Expression _predicate;
11+
12+
/// <summary>
13+
/// Initializes a new instance of the <see cref="T:NhHavingClause" /> class.
14+
/// </summary>
15+
/// <param name="predicate">The predicate used to filter data items.</param>
16+
public NhHavingClause(Expression predicate)
17+
{
18+
if (predicate == null) throw new ArgumentNullException(nameof(predicate));
19+
_predicate = predicate;
20+
}
21+
22+
/// <summary>
23+
/// Gets the predicate, the expression representing the where condition by which the data items are filtered
24+
/// </summary>
25+
public Expression Predicate
26+
{
27+
get { return _predicate; }
28+
set
29+
{
30+
if (value == null) throw new ArgumentNullException(nameof(value));
31+
_predicate = value;
32+
}
33+
}
34+
35+
protected override void Accept(INhQueryModelVisitor visitor, QueryModel queryModel, int index)
1136
{
37+
visitor.VisitNhHavingClause(this, queryModel, index);
38+
}
39+
40+
/// <inheritdoc />
41+
IBodyClause IBodyClause.Clone(CloneContext cloneContext)
42+
{
43+
return Clone(cloneContext);
44+
}
45+
46+
/// <summary>
47+
/// Transforms all the expressions in this clause and its child objects via the given
48+
/// <paramref name="transformation" /> delegate.
49+
/// </summary>
50+
/// <param name="transformation">
51+
/// The transformation object. This delegate is called for each <see cref="T:System.Linq.Expressions.Expression" />
52+
/// within this
53+
/// clause, and those expressions will be replaced with what the delegate returns.
54+
/// </param>
55+
public void TransformExpressions(Func<Expression, Expression> transformation)
56+
{
57+
if (transformation == null) throw new ArgumentNullException(nameof(transformation));
58+
Predicate = transformation(Predicate);
1259
}
1360

1461
public override string ToString()
1562
{
16-
return "having " + FormattingExpressionTreeVisitor.Format(Predicate);
63+
return "having " + Predicate;
64+
}
65+
66+
/// <summary>Clones this clause.</summary>
67+
/// <param name="cloneContext">
68+
/// The clones of all query source clauses are registered with this
69+
/// <see cref="T:Remotion.Linq.Clauses.CloneContext" />.
70+
/// </param>
71+
/// <returns></returns>
72+
public NhHavingClause Clone(CloneContext cloneContext)
73+
{
74+
if (cloneContext == null) throw new ArgumentNullException(nameof(cloneContext));
75+
return new NhHavingClause(Predicate);
1776
}
1877
}
19-
}
78+
}

src/NHibernate/Linq/Clauses/NhJoinClause.cs

Lines changed: 126 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,60 +3,166 @@
33
using System.Collections.ObjectModel;
44
using System.Linq.Expressions;
55
using NHibernate.Linq.Visitors;
6+
using Remotion.Linq;
67
using Remotion.Linq.Clauses;
78
using Remotion.Linq.Clauses.Expressions;
89

910
namespace NHibernate.Linq.Clauses
1011
{
1112
/// <summary>
12-
/// All joins are created as outer joins. An optimization in <see cref="WhereJoinDetector"/> finds
13-
/// joins that may be inner joined and calls <see cref="MakeInner"/> on them.
14-
/// <see cref="QueryModelVisitor"/>'s <see cref="QueryModelVisitor.VisitAdditionalFromClause"/> will
15-
/// then emit the correct HQL join.
13+
/// All joins are created as outer joins. An optimization in <see cref="WhereJoinDetector" /> finds
14+
/// joins that may be inner joined and calls <see cref="MakeInner" /> on them.
15+
/// <see cref="QueryModelVisitor" />'s <see cref="QueryModelVisitor.VisitAdditionalFromClause" /> will
16+
/// then emit the correct HQL join.
1617
/// </summary>
17-
public class NhJoinClause : AdditionalFromClause
18+
public class NhJoinClause : NhClauseBase, IFromClause, IBodyClause
1819
{
20+
Expression _fromExpression;
21+
string _itemName;
22+
System.Type _itemType;
23+
1924
public NhJoinClause(string itemName, System.Type itemType, Expression fromExpression)
2025
: this(itemName, itemType, fromExpression, new NhWithClause[0])
2126
{
2227
}
2328

29+
/// <summary>
30+
/// Initializes a new instance of the <see cref="T:Remotion.Linq.Clauses.NhJoinClause" /> class.
31+
/// </summary>
32+
/// <param name="itemName">A name describing the items generated by the from clause.</param>
33+
/// <param name="itemType">The type of the items generated by the from clause.</param>
34+
/// <param name="fromExpression">
35+
/// The <see cref="T:System.Linq.Expressions.Expression" /> generating data items for this
36+
/// from clause.
37+
/// </param>
38+
/// <param name="restrictions"></param>
2439
public NhJoinClause(string itemName, System.Type itemType, Expression fromExpression, IEnumerable<NhWithClause> restrictions)
25-
: base(itemName, itemType, fromExpression)
2640
{
27-
Restrictions = new ObservableCollection<NhWithClause>();
28-
foreach (var withClause in restrictions)
29-
Restrictions.Add(withClause);
41+
if (string.IsNullOrEmpty(itemName)) throw new ArgumentException("Value cannot be null or empty.", nameof(itemName));
42+
if (itemType == null) throw new ArgumentNullException(nameof(itemType));
43+
if (fromExpression == null) throw new ArgumentNullException(nameof(fromExpression));
44+
45+
_itemName = itemName;
46+
_itemType = itemType;
47+
_fromExpression = fromExpression;
48+
49+
Restrictions = new ObservableCollection<NhWithClause>(restrictions);
3050
IsInner = false;
3151
}
3252

33-
public ObservableCollection<NhWithClause> Restrictions { get; private set; }
53+
public ObservableCollection<NhWithClause> Restrictions { get; }
3454

3555
public bool IsInner { get; private set; }
3656

37-
public override AdditionalFromClause Clone(CloneContext cloneContext)
57+
public void TransformExpressions(Func<Expression, Expression> transformation)
3858
{
39-
var joinClause = new NhJoinClause(ItemName, ItemType, FromExpression);
59+
if (transformation == null) throw new ArgumentNullException(nameof(transformation));
4060
foreach (var withClause in Restrictions)
61+
withClause.TransformExpressions(transformation);
62+
FromExpression = transformation(FromExpression);
63+
}
64+
65+
/// <summary>
66+
/// Accepts the specified visitor by calling its
67+
/// <see
68+
/// cref="M:Remotion.Linq.IQueryModelVisitor.VisitAdditionalFromClause(Remotion.Linq.Clauses.AdditionalFromClause,Remotion.Linq.QueryModel,System.Int32)" />
69+
/// method.
70+
/// </summary>
71+
/// <param name="visitor">The visitor to accept.</param>
72+
/// <param name="queryModel">The query model in whose context this clause is visited.</param>
73+
/// <param name="index">
74+
/// The index of this clause in the <paramref name="queryModel" />'s
75+
/// <see cref="P:Remotion.Linq.QueryModel.BodyClauses" /> collection.
76+
/// </param>
77+
protected override void Accept(INhQueryModelVisitor visitor, QueryModel queryModel, int index)
78+
{
79+
visitor.VisitNhJoinClause(this, queryModel, index);
80+
}
81+
82+
IBodyClause IBodyClause.Clone(CloneContext cloneContext)
83+
{
84+
return Clone(cloneContext);
85+
}
86+
87+
/// <summary>
88+
/// Gets or sets a name describing the items generated by this from clause.
89+
/// </summary>
90+
/// <remarks>
91+
/// Item names are inferred when a query expression is parsed, and they usually correspond to the variable names
92+
/// present in that expression.
93+
/// However, note that names are not necessarily unique within a <see cref="T:Remotion.Linq.QueryModel" />. Use names
94+
/// only for readability and debugging, not for
95+
/// uniquely identifying <see cref="T:Remotion.Linq.Clauses.IQuerySource" /> objects. To match an
96+
/// <see cref="T:Remotion.Linq.Clauses.IQuerySource" /> with its references, use the
97+
/// <see cref="P:Remotion.Linq.Clauses.Expressions.QuerySourceReferenceExpression.ReferencedQuerySource" /> property
98+
/// rather than the <see cref="P:Remotion.Linq.Clauses.NhFromClauseBase.ItemName" />.
99+
/// </remarks>
100+
public string ItemName
101+
{
102+
get { return _itemName; }
103+
set
104+
{
105+
if (string.IsNullOrEmpty(value)) throw new ArgumentException("Value cannot be null or empty.", nameof(value));
106+
_itemName = value;
107+
}
108+
}
109+
110+
/// <summary>
111+
/// Gets or sets the type of the items generated by this from clause.
112+
/// </summary>
113+
/// <note type="warning">
114+
/// Changing the <see cref="P:Remotion.Linq.Clauses.NhFromClauseBase.ItemType" /> of a
115+
/// <see cref="T:Remotion.Linq.Clauses.IQuerySource" /> can make all
116+
/// <see cref="T:Remotion.Linq.Clauses.Expressions.QuerySourceReferenceExpression" /> objects that
117+
/// point to that <see cref="T:Remotion.Linq.Clauses.IQuerySource" /> invalid, so the property setter should be used
118+
/// with care.
119+
/// </note>
120+
public System.Type ItemType
121+
{
122+
get { return _itemType; }
123+
set
41124
{
42-
var withClause2 = new NhWithClause(withClause.Predicate);
43-
joinClause.Restrictions.Add(withClause2);
125+
if (value == null) throw new ArgumentNullException(nameof(value));
126+
_itemType = value;
44127
}
128+
}
45129

130+
/// <summary>
131+
/// The expression generating the data items for this from clause.
132+
/// </summary>
133+
public Expression FromExpression
134+
{
135+
get { return _fromExpression; }
136+
set
137+
{
138+
if (value == null) throw new ArgumentNullException(nameof(value));
139+
_fromExpression = value;
140+
}
141+
}
142+
143+
public void CopyFromSource(IFromClause source)
144+
{
145+
if (source == null) throw new ArgumentNullException(nameof(source));
146+
FromExpression = source.FromExpression;
147+
ItemName = source.ItemName;
148+
ItemType = source.ItemType;
149+
}
150+
151+
public NhJoinClause Clone(CloneContext cloneContext)
152+
{
153+
var joinClause = new NhJoinClause(ItemName, ItemType, FromExpression, Restrictions);
46154
cloneContext.QuerySourceMapping.AddMapping(this, new QuerySourceReferenceExpression(joinClause));
47-
return base.Clone(cloneContext);
155+
return joinClause;
48156
}
49157

50158
public void MakeInner()
51159
{
52160
IsInner = true;
53161
}
54162

55-
public override void TransformExpressions(Func<Expression, Expression> transformation)
163+
public override string ToString()
56164
{
57-
foreach (var withClause in Restrictions)
58-
withClause.TransformExpressions(transformation);
59-
base.TransformExpressions(transformation);
165+
return string.Format("join {0} {1} in {2}", ItemType.Name, ItemName, FromExpression);
60166
}
61167
}
62-
}
168+
}

0 commit comments

Comments
 (0)