13
13
using Remotion . Linq . Parsing . Structure . IntermediateModel ;
14
14
using Remotion . Linq . Parsing . Structure . NodeTypeProviders ;
15
15
using Remotion . Linq . Parsing . Structure . ExpressionTreeProcessors ;
16
+ using NHibernate . Linq . Visitors ;
16
17
17
18
namespace NHibernate . Linq
18
19
{
19
20
public static class NhRelinqQueryParser
20
21
{
21
22
private static readonly QueryParser QueryParser ;
23
+ private static readonly IExpressionTreeProcessor PreProcessor ;
22
24
23
25
static NhRelinqQueryParser ( )
24
26
{
27
+ var preTransformerRegistry = new ExpressionTransformerRegistry ( ) ;
28
+ // NH-3247: must remove .Net compiler char to int conversion before
29
+ // parameterization occurs.
30
+ preTransformerRegistry . Register ( new RemoveCharToIntConversion ( ) ) ;
31
+ PreProcessor = new TransformingExpressionTreeProcessor ( preTransformerRegistry ) ;
32
+
25
33
var transformerRegistry = ExpressionTransformerRegistry . CreateDefault ( ) ;
26
- transformerRegistry . Register ( new RemoveCharToIntConversion ( ) ) ;
27
34
transformerRegistry . Register ( new RemoveRedundantCast ( ) ) ;
28
35
transformerRegistry . Register ( new SimplifyCompareTransformer ( ) ) ;
29
36
30
37
// If needing a compound processor for adding other processing, do not use
31
38
// ExpressionTreeParser.CreateDefaultProcessor(transformerRegistry), it would
32
39
// cause NH-3961 again by including a PartialEvaluatingExpressionTreeProcessor.
33
- // Directly instanciate a CompoundExpressionTreeProcessor instead.
40
+ // Directly instantiate a CompoundExpressionTreeProcessor instead.
34
41
var processor = new TransformingExpressionTreeProcessor ( transformerRegistry ) ;
35
42
36
43
var nodeTypeProvider = new NHibernateNodeTypeProvider ( ) ;
@@ -39,6 +46,18 @@ static NhRelinqQueryParser()
39
46
QueryParser = new QueryParser ( expressionTreeParser ) ;
40
47
}
41
48
49
+ /// <summary>
50
+ /// Applies the minimal transformations required before parameterization,
51
+ /// expression key computing and parsing.
52
+ /// </summary>
53
+ /// <param name="expression">The expression to transform.</param>
54
+ /// <returns>The transformed expression.</returns>
55
+ public static Expression PreTransform ( Expression expression )
56
+ {
57
+ var partiallyEvaluatedExpression = NhPartialEvaluatingExpressionTreeVisitor . EvaluateIndependentSubtrees ( expression ) ;
58
+ return PreProcessor . Process ( partiallyEvaluatedExpression ) ;
59
+ }
60
+
42
61
public static QueryModel Parse ( Expression expression )
43
62
{
44
63
return QueryParser . GetParsedQuery ( expression ) ;
0 commit comments