internal ICompiledQuerySource GetCompiledQuerySourceFor <TDoc, TOut>(ICompiledQuery <TDoc, TOut> query,
                                                                             QuerySession session)
        {
            if (_querySources.TryFind(query.GetType(), out var source))
            {
                return(source);
            }

            if (typeof(TOut).CanBeCastTo <Task>())
            {
                throw InvalidCompiledQueryException.ForCannotBeAsync(query.GetType());
            }

            var plan = QueryCompiler.BuildPlan(session, query, _store.Options);
            var file = new CompiledQueryCodeFile(query.GetType(), _store, plan, _tracking);

            var rules = _store.Options.CreateGenerationRules();

            rules.ReferenceTypes(typeof(TDoc), typeof(TOut), query.GetType());

            file.InitializeSynchronously(rules, _store, null);

            source        = file.Build(rules);
            _querySources = _querySources.AddOrUpdate(query.GetType(), source);

            return(source);
        }
Beispiel #2
0
        internal ICompiledQuerySource GetCompiledQuerySourceFor <TDoc, TOut>(ICompiledQuery <TDoc, TOut> query, IMartenSession session)
        {
            if (_querySources.TryFind(query.GetType(), out var source))
            {
                return(source);
            }

            if (typeof(TOut).CanBeCastTo <Task>())
            {
                throw InvalidCompiledQueryException.ForCannotBeAsync(query.GetType());
            }

            var plan = QueryCompiler.BuildPlan(session, query, this);

            source        = new CompiledQuerySourceBuilder(plan, this).Build();
            _querySources = _querySources.AddOrUpdate(query.GetType(), source);

            return(source);
        }