Beispiel #1
0
        public IASTNode Translate(ISessionFactoryImplementor sessionFactory, bool filter)
        {
            if (ExpressionToHqlTranslationResults != null)
            {
                // Query has already been translated. Arguments do not really matter, because queries are anyway tied
                // to a single session factory and cannot switch from being a filter query (query on a mapped collection)
                // or not.
                return(DuplicateTree(ExpressionToHqlTranslationResults.Statement.AstNode));
            }

            var requiredHqlParameters = new List <NamedParameterDescriptor>();
            var queryModel            = NhRelinqQueryParser.Parse(_expression);
            var visitorParameters     = new VisitorParameters(sessionFactory, _constantToParameterMap, requiredHqlParameters,
                                                              new QuerySourceNamer(), TargetType, QueryMode);

            ExpressionToHqlTranslationResults = QueryModelVisitor.GenerateHqlQuery(queryModel, visitorParameters, true, ReturnType);

            if (ExpressionToHqlTranslationResults.ExecuteResultTypeOverride != null)
            {
                Type = ExpressionToHqlTranslationResults.ExecuteResultTypeOverride;
            }

            ParameterDescriptors = requiredHqlParameters.AsReadOnly();

            CanCachePlan = CanCachePlan &&
                           // If some constants do not have matching HQL parameters, their values from first query will
                           // be embedded in the plan and reused for subsequent queries: do not cache the plan.
                           !ParameterValuesByName
                           .Keys
                           .Except(requiredHqlParameters.Select(p => p.Name))
                           .Any();

            // The ast node may be altered by caller, duplicate it for preserving the original one.
            return(DuplicateTree(ExpressionToHqlTranslationResults.Statement.AstNode));
        }
Beispiel #2
0
 internal void CopyExpressionTranslation(NhLinqExpression other)
 {
     ExpressionToHqlTranslationResults = other.ExpressionToHqlTranslationResults;
     ParameterDescriptors = other.ParameterDescriptors;
     // Type could have been overridden by translation.
     Type = other.Type;
 }