Skip to content

Commit 3d30fb3

Browse files
Additional optimization.
1 parent cb77f4a commit 3d30fb3

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

src/NHibernate/Async/Impl/ExpressionQueryImpl.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using NHibernate.Hql.Ast.ANTLR;
1818
using NHibernate.Hql.Ast.ANTLR.Tree;
1919
using NHibernate.Hql.Ast.ANTLR.Util;
20+
using NHibernate.Linq;
2021
using NHibernate.Type;
2122
using NHibernate.Util;
2223

src/NHibernate/Impl/ExpressionQueryImpl.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using NHibernate.Hql.Ast.ANTLR;
88
using NHibernate.Hql.Ast.ANTLR.Tree;
99
using NHibernate.Hql.Ast.ANTLR.Util;
10+
using NHibernate.Linq;
1011
using NHibernate.Type;
1112
using NHibernate.Util;
1213

@@ -27,7 +28,7 @@ protected ExpressionQueryImpl(
2728
_isFilter = isFilter;
2829
}
2930

30-
public IQueryExpression QueryExpression { get; private set; }
31+
public IQueryExpression QueryExpression { get; }
3132

3233
protected readonly bool _isFilter;
3334

@@ -81,10 +82,15 @@ protected override IQueryExpression ExpandParameters(IDictionary<string, TypedVa
8182
return QueryExpression;
8283
}
8384

84-
//TODO: Do we need to translate expression one more time here?
85-
// This is not much an issue anymore: ExpressionQueryImpl are currently created only with NhLinqExpression
86-
// which do cache their translation.
87-
var newTree = ParameterExpander.Expand(QueryExpression.Translate(Session.Factory, _isFilter), map);
85+
// Translating expression one more time here is not much an issue anymore: when using the default Linq
86+
// provider, ExpressionQueryImpl are created only with NhLinqExpression, which do cache their translation.
87+
var newTree = ParameterExpander.Expand(
88+
QueryExpression is NhLinqExpression linqExpr ?
89+
// Avoid cloning, the parameter expander does (and need to) clone too.
90+
linqExpr.Translate(Session.Factory, _isFilter, false) :
91+
// A custom Linq provider may supply something else than a NhLinqExpression, support it.
92+
QueryExpression.Translate(Session.Factory, _isFilter),
93+
map);
8894
var key = new StringBuilder(QueryExpression.Key);
8995

9096
foreach (var pair in map)
@@ -201,7 +207,7 @@ private IASTNode Expand()
201207
var parameters = ParameterDetector.LocateParameters(_tree, new HashSet<string>(_map.Keys));
202208
var nodeMapping = new Dictionary<IASTNode, IEnumerable<IASTNode>>();
203209

204-
foreach (IASTNode param in parameters)
210+
foreach (var param in parameters)
205211
{
206212
var paramName = param.GetChild(0);
207213
var aliases = _map[paramName.Text];

src/NHibernate/Linq/NhLinqExpression.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ public NhLinqExpression(Expression expression, ISessionFactoryImplementor sessio
6767
}
6868

6969
public IASTNode Translate(ISessionFactoryImplementor sessionFactory, bool filter)
70+
=> Translate(sessionFactory, filter, true);
71+
72+
public IASTNode Translate(ISessionFactoryImplementor sessionFactory, bool filter, bool yieldClone)
7073
{
7174
if (ExpressionToHqlTranslationResults != null)
7275
{

0 commit comments

Comments
 (0)