/// <summary> /// Compile IQueryPartsContainer to a QueryString /// </summary> /// <param name="container">The container containing all queryparts to compile to sql</param> /// <param name="interceptors">The collection of interceptors</param> /// <returns>The Compiled query</returns> public virtual CompiledQuery Compile(IQueryPartsContainer container, InterceptorCollection interceptors) { _compiledParts = new HashSet<IQueryPart>(); if (container.AggregatePart != null) { var interception = new InterceptionHandler(interceptors, container.AggregatePart.EntityType); interception.ExecuteBeforeCompile(container); } using (var writer = new StringWriter()) { foreach (var part in container.Parts) { CompilePart(part, writer, container); } var query = writer.ToString(); return new CompiledQuery { QueryString = query, QueryParts = container }; } }
protected void CompileChildParts(IQueryPart part, TextWriter writer, IQueryPartsContainer container) { if (_compiledParts.AsParallel().Contains(part)) { return; } _compiledParts.Add(part); foreach (var p in part.Parts) { CompilePart(p, writer, container, part); } }
/// <summary> /// Creates a command object /// </summary> /// <param name="map">The query parts</param> public QueryCommand(IQueryPartsContainer map) { QueryParts = map; }
protected virtual void CompilePart(IQueryPart part, TextWriter writer, IQueryPartsContainer container, IQueryPart parent = null) { var compiler = _compilers[part.OperationType]; compiler(part, writer, container, parent); CompileChildParts(part, writer, container); }