Example #1
0
        public string SourceCodeForCompiledQuery(Type type)
        {
            if (!type.Closes(typeof(ICompiledQuery <,>)))
            {
                throw new ArgumentOutOfRangeException(nameof(type), "Not a compiled query type");
            }

            var assembly = new GeneratedAssembly(new GenerationRules(SchemaConstants.MartenGeneratedNamespace));

            using var session = _store.LightweightSession();
            var plan    = QueryCompiler.BuildPlan((IMartenSession)session, type, _store.Options);
            var builder = new CompiledQuerySourceBuilder(plan, _store.Options);

            var(sourceType, handlerType) = builder.AssemblyType(assembly);

            return(assembly.GenerateCode());
        }
Example #2
0
        public IServiceVariableSource AssemblyTypes(GenerationRules rules, GeneratedAssembly assembly)
        {
            // This is important to ensure that all the possible DocumentMappings exist
            // first
            Storage.BuildAllMappings();
            foreach (var mapping in Storage.AllDocumentMappings)
            {
                var builder = new DocumentPersistenceBuilder(mapping, this);
                builder.AssemblyTypes(assembly);
            }

            if (_compiledQueryTypes.Any())
            {
                using var session = new LightweightSession(this);
                foreach (var compiledQueryType in _compiledQueryTypes)
                {
                    var plan    = QueryCompiler.BuildPlan(session, compiledQueryType, this);
                    var builder = new CompiledQuerySourceBuilder(plan, this);
                    builder.AssemblyType(assembly);
                }
            }

            return(null);
        }