Пример #1
0
        private object ExecuteAggregateQuery(QueryContextsEntry queryContextsEntry, string field, AggregateType aggregateType)
        {
            Type            t = queryContextsEntry.Type;
            IQueryGenerator queryGenerator = ConfigContainer.Resolve <IQueryGenerator>();
            string          generatedQuery = queryGenerator.GenerateAggregateQueryString(field, queryContextsEntry, this.expressionTree, this.queryContextsForTypes.Count > 1, aggregateType);

            using (IPersistenceHandler persistenceHandler = this.pm.PersistenceHandlerManager.GetPersistenceHandler(t))
            {
                persistenceHandler.VerboseMode = this.pm.VerboseMode;
                persistenceHandler.LogAdapter  = this.pm.LogAdapter;
                this.pm.CheckTransaction(persistenceHandler, t);

                // Note, that we can't execute all subQueries in one batch, because
                // the subqueries could be executed against different connections.
                // TODO: This could be optimized, if we made clear whether the involved tables
                // can be reached with the same connection.
                var l = persistenceHandler.ExecuteBatch(new string[] { generatedQuery }, this.parameters);
                if (l.Count == 0)
                {
                    return(null);
                }

                return((l[0])["AggrResult"]);
            }
        }