Пример #1
0
        // Constructors

// ReSharper disable MemberCanBeProtected.Global
        public SubQuery(ProjectionExpression projectionExpression, TranslatedQuery query, Parameter <Tuple> parameter, Tuple tuple, ItemMaterializationContext context)
// ReSharper restore MemberCanBeProtected.Global
        {
            this.provider = context.Session.Query.Provider;
            var tupleParameterBindings = new Dictionary <Parameter <Tuple>, Tuple>(projectionExpression.TupleParameterBindings);
            var currentTranslatedQuery = query;

            var outerParameterContext = context.ParameterContext;
            var parameterContext      = new ParameterContext(outerParameterContext);

            // Gather Parameter<Tuple> values from current ParameterScope for future use.
            outerParameterContext.SetValue(parameter, tuple);
            foreach (var tupleParameter in currentTranslatedQuery.TupleParameters)
            {
                var value = outerParameterContext.GetValue(tupleParameter);
                tupleParameterBindings[tupleParameter] = value;
                parameterContext.SetValue(tupleParameter, value);
            }

            this.projectionExpression = new ProjectionExpression(
                projectionExpression.Type,
                projectionExpression.ItemProjector,
                tupleParameterBindings,
                projectionExpression.ResultAccessMethod);
            var translatedQuery = new TranslatedQuery(
                query.DataSource,
                query.Materializer,
                query.ResultAccessMethod,
                tupleParameterBindings,
                EnumerableUtils <Parameter <Tuple> > .Empty);

            delayedQuery = new DelayedQuery <TElement>(context.Session, translatedQuery, parameterContext);
            context.Session.RegisterUserDefinedDelayedQuery(delayedQuery.Task);
            context.MaterializationContext.MaterializationQueue.Enqueue(MaterializeSelf);
        }
        private TranslatedQuery Translate(ProjectionExpression projection,
                                          IEnumerable <Parameter <Tuple> > tupleParameterBindings)
        {
            var newItemProjector = projection.ItemProjector.EnsureEntityIsJoined();
            var result           = new ProjectionExpression(
                projection.Type,
                newItemProjector,
                projection.TupleParameterBindings,
                projection.ResultAccessMethod);
            var optimized = Optimize(result);

            // Prepare cached query, if required
            var prepared = compiledQueryScope != null
        ? PrepareCachedQuery(optimized, compiledQueryScope)
        : optimized;

            // Compilation
            var dataSource = prepared.ItemProjector.DataSource;
            var compiled   = context.Domain.Handler.CompilationService.Compile(dataSource, context.RseCompilerConfiguration);

            // Build materializer
            var materializer    = BuildMaterializer(prepared, tupleParameterBindings);
            var translatedQuery = new TranslatedQuery(
                compiled, materializer, prepared.ResultAccessMethod,
                projection.TupleParameterBindings, tupleParameterBindings);

            // Providing the result to caching layer, if required
            if (compiledQueryScope != null && translatedQuery.TupleParameters.Count == 0)
            {
                var parameterizedQuery = new ParameterizedQuery(
                    translatedQuery,
                    compiledQueryScope.QueryParameter);
                compiledQueryScope.ParameterizedQuery = parameterizedQuery;
                return(parameterizedQuery);
            }

            return(translatedQuery);
        }
Пример #3
0
        // Constructors

// ReSharper disable MemberCanBeProtected.Global
        public SubQuery(ProjectionExpression projectionExpression, TranslatedQuery query, Parameter <Tuple> parameter, Tuple tuple, ItemMaterializationContext context)
// ReSharper restore MemberCanBeProtected.Global
        {
            this.provider = context.Session.Query.Provider;
            var tupleParameterBindings = new Dictionary <Parameter <Tuple>, Tuple>(projectionExpression.TupleParameterBindings);
            var currentTranslatedQuery = ((TranslatedQuery <IEnumerable <TElement> >)query);

            // Gather Parameter<Tuple> values from current ParameterScope for future use.
            parameter.Value = tuple;
            foreach (var tupleParameter in currentTranslatedQuery.TupleParameters)
            {
                var value = tupleParameter.Value;
                tupleParameterBindings[tupleParameter] = value;
            }
            var parameterContext = new ParameterContext();

            using (parameterContext.Activate())
                foreach (var tupleParameter in currentTranslatedQuery.TupleParameters)
                {
                    tupleParameter.Value = tupleParameter.Value;
                }

            this.projectionExpression = new ProjectionExpression(
                projectionExpression.Type,
                projectionExpression.ItemProjector,
                tupleParameterBindings,
                projectionExpression.ResultType);
            var translatedQuery = new TranslatedQuery <IEnumerable <TElement> >(
                query.DataSource,
                (Func <IEnumerable <Tuple>, Session, Dictionary <Parameter <Tuple>, Tuple>, ParameterContext, IEnumerable <TElement> >)query.UntypedMaterializer,
                tupleParameterBindings,
                EnumerableUtils <Parameter <Tuple> > .Empty);

            delayedSequence = new DelayedSequence <TElement>(context.Session, translatedQuery, parameterContext);
            context.Session.RegisterUserDefinedDelayedQuery(delayedSequence.Task);
            context.MaterializationContext.MaterializationQueue.Enqueue(MaterializeSelf);
        }
 public ParameterizedQuery(TranslatedQuery translatedQuery, Parameter parameter)
     : base(translatedQuery.DataSource, translatedQuery.Materializer, translatedQuery.ResultAccessMethod)
 {
     QueryParameter = parameter;
 }
 public ParameterizedQuery(TranslatedQuery <TResult> translatedQuery, Parameter parameter)
     : base(translatedQuery.DataSource, translatedQuery.Materializer)
 {
     QueryParameter = parameter;
 }
Пример #6
0
 static TResult ExecuteScalarQuery(TranslatedQuery query, Session session, ParameterContext parameterContext)
 {
     return(query.ExecuteScalar <TResult>(session, parameterContext));
 }
Пример #7
0
 public Grouping(ProjectionExpression projectionExpression, TranslatedQuery translatedQuery, Parameter <Tuple> parameter, Tuple tuple, TKey key, ItemMaterializationContext context)
     : base(projectionExpression, translatedQuery, parameter, tuple, context)
 {
     Key = key;
 }