Example #1
0
        private IList ExecuteSubQuery(Type t, QueryContextsEntry queryContextsEntry)
        {
            IQueryGenerator queryGenerator  = ConfigContainer.Resolve <IQueryGenerator>();
            bool            hasBeenPrepared = PrepareParameters();
            string          generatedQuery;

            if (this.queryLanguage == QueryLanguage.NDOql)
            {
                generatedQuery = queryGenerator.GenerateQueryString(queryContextsEntry, this.expressionTree, this.hollowResults, this.queryContextsForTypes.Count > 1, this.orderings, this.skip, this.take);
            }
            else
            {
                generatedQuery = (string)this.expressionTree.Value;
            }

            if (hasBeenPrepared)
            {
                WriteBackParameters();
            }

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

                DataTable table = persistenceHandler.PerformQuery(generatedQuery, this.parameters, this.pm.DataSet);
                return(pm.DataTableToIList(t, table.Rows, this.hollowResults));
            }
        }
Example #2
0
        private List <ObjectRowPair <T> > ExecuteOrderedSubQuery(QueryContextsEntry queryContextsEntry)
        {
            Type      t = queryContextsEntry.Type;
            Class     resultSubClass = this.pm.GetClass(t);
            DataTable comparismTable = new DataTable("ComparismTable");

            foreach (QueryOrder order in this.orderings)
            {
                DataColumn col = comparismTable.Columns.Add(order.FieldName);
                if (order.IsAscending)
                {
                    col.AutoIncrementStep = 1;
                }
                else
                {
                    col.AutoIncrementStep = -1;
                }
            }

            DataTable table = null;

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

                bool            hasBeenPrepared = PrepareParameters();
                IQueryGenerator queryGenerator  = ConfigContainer.Resolve <IQueryGenerator>();
                string          generatedQuery  = queryGenerator.GenerateQueryString(queryContextsEntry, this.expressionTree, this.hollowResults, this.queryContextsForTypes.Count > 1, this.orderings, this.skip, this.take);

                if (hasBeenPrepared)
                {
                    WriteBackParameters();
                }

                table = persistenceHandler.PerformQuery(generatedQuery, this.parameters, this.pm.DataSet);
            }

            DataRow[] rows    = table.Select();
            var       objects = pm.DataTableToIList(t, rows, this.hollowResults);
            List <ObjectRowPair <T> > result = new List <ObjectRowPair <T> >(objects.Count);
            int       i        = 0;
            IProvider provider = mappings.GetProvider(t);

            foreach (T obj in objects)
            {
                DataRow row    = rows[i++];
                DataRow newRow = comparismTable.NewRow();
                foreach (QueryOrder order in this.orderings)
                {
                    string newColumnName = order.FieldName;
                    if (!comparismTable.Columns.Contains(newColumnName))
                    {
                        throw new InternalException(558, "Query.cs - Column not found.");
                    }
                    string oldColumnName = resultSubClass.FindField(order.FieldName).Column.Name;
                    if (!table.Columns.Contains(oldColumnName))
                    {
                        throw new InternalException(561, "Query.cs - Column not found.");
                    }
                    newRow[newColumnName] = row[oldColumnName];
                }
                result.Add(new ObjectRowPair <T>(obj, newRow));
            }

            return(result);
        }