Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix NH-3239 by moving NameUnNamedParameters call after key generation.

Also NameUnNamedParameters should be removed when https://www.re-motion.org/jira/browse/RM-5107 will be fixed.
  • Loading branch information...
commit 2fa170864cd628f850a9628c845740b31b0ec4d0 1 parent e1ff273
@hazzik hazzik authored
View
20 src/NHibernate.Test/Linq/DynamicQueryTests.cs
@@ -1,5 +1,6 @@
using System.Linq;
using System.Linq.Dynamic;
+using NHibernate.Linq;
using NUnit.Framework;
namespace NHibernate.Test.Linq
@@ -17,5 +18,24 @@ public void CanQueryWithDynamicOrderBy()
Assert.That(list, Is.Ordered.By("RegisteredAt"));
}
+
+ [Test(Description = "NH-3239")]
+ public void CanCahceDynamicLinq()
+ {
+ //dynamic orderby clause
+ var users = db.Users
+ .Cacheable()
+ .Fetch(x => x.Role)
+ .OrderBy("RegisteredAt");
+
+ users
+ .ToList();
+
+ using (var log = new SqlLogSpy())
+ {
+ users.ToList();
+ Assert.IsNullOrEmpty(log.GetWholeLog());
+ }
+ }
}
}
View
3  src/NHibernate/Linq/NhLinqExpression.cs
@@ -30,7 +30,6 @@ public class NhLinqExpression : IQueryExpression
public NhLinqExpression(Expression expression, ISessionFactory sessionFactory)
{
_expression = NhPartialEvaluatingExpressionTreeVisitor.EvaluateIndependentSubtrees(expression);
- _expression = NameUnNamedParameters.Visit(_expression);
_constantToParameterMap = ExpressionParameterVisitor.Visit(_expression, sessionFactory);
@@ -56,7 +55,7 @@ public IASTNode Translate(ISessionFactoryImplementor sessionFactory)
{
var requiredHqlParameters = new List<NamedParameterDescriptor>();
var querySourceNamer = new QuerySourceNamer();
- var queryModel = NhRelinqQueryParser.Parse(_expression);
+ var queryModel = NhRelinqQueryParser.Parse(NameUnNamedParameters.Visit(_expression));
var visitorParameters = new VisitorParameters(sessionFactory, _constantToParameterMap, requiredHqlParameters, querySourceNamer);
ExpressionToHqlTranslationResults = QueryModelVisitor.GenerateHqlQuery(queryModel, visitorParameters, true);
View
1  src/NHibernate/Linq/Visitors/NameUnNamedParameters.cs
@@ -5,6 +5,7 @@
namespace NHibernate.Linq.Visitors
{
+ //TODO: Remove this visitor when https://www.re-motion.org/jira/browse/RM-5107 will be fixed
public class NameUnNamedParameters : ExpressionTreeVisitor
{
public static Expression Visit(Expression expression)
Please sign in to comment.
Something went wrong with that request. Please try again.