Skip to content

Commit 4dfff6a

Browse files
authored
Avoid lambda compilation for member access expressions in LINQ (#2948)
Fixes #2947
1 parent b13c01a commit 4dfff6a

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/NHibernate/Linq/Visitors/NhPartialEvaluatingExpressionVisitor.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
using System;
1919
using System.Linq;
2020
using System.Linq.Expressions;
21+
using System.Reflection;
2122
using NHibernate.Collection;
2223
using NHibernate.Engine;
24+
using NHibernate.Impl;
2325
using NHibernate.Linq.Functions;
2426
using NHibernate.Util;
2527
using Remotion.Linq.Parsing;
@@ -143,13 +145,14 @@ private Expression EvaluateSubtree(Expression subtree)
143145

144146
return constantExpression;
145147
}
146-
else
147-
{
148-
Expression<Func<object>> lambdaWithoutParameters = Expression.Lambda<Func<object>>(Expression.Convert(subtree, typeof(object)));
149-
var compiledLambda = lambdaWithoutParameters.Compile();
150148

151-
object value = compiledLambda();
152-
return Expression.Constant(value, subtree.Type);
149+
try
150+
{
151+
return Expression.Constant(ExpressionProcessor.FindValue(subtree), subtree.Type);
152+
}
153+
catch (TargetInvocationException ex)
154+
{
155+
throw ReflectHelper.UnwrapTargetInvocationException(ex);
153156
}
154157
}
155158

0 commit comments

Comments
 (0)