Beispiel #1
0
        public PagedDataSet GetPagedDataSet(IFinder finder, Int32 Page, Int32 RecordsPerPage)
        {
            using (IDbConnection connection = OpenConnection())
            {
                try
                {
#if DEBUG
                    Stopwatch sw = new Stopwatch();
                    sw.Start();
#endif
                    PagedDataSet ds = new PagedDataSet(finder.Table);

                    using (IDbCommand command = finder.CountCommand)
                    {
                        command.Connection = connection;
                        int numRecords = (int)command.ExecuteScalar();
                        ds.PagingInfo = new PagingInfo(numRecords, Page, RecordsPerPage);
#if DEBUG
                        LogMessage("GetPagedDataSet", finder.CountCommand, sw.ElapsedMilliseconds);
#endif
                    }

                    using (IDbCommand command = finder.FindCommand)
                    {
                        command.Connection = connection;
                        DbDataAdapter da = m_factory.CreateAdapter(command);
                        da.Fill(ds, ds.PagingInfo.StartRecord - 1, ds.PagingInfo.PageSize, finder.Table);
#if DEBUG
                        LogMessage("GetPagedDataSet", finder.FindCommand, sw.ElapsedMilliseconds);
#endif
                    }
#if DEBUG
                    sw.Stop();
#endif
                    return(ds);
                }
                finally
                {
                    CloseConnection(connection);
                }
            }
        }
Beispiel #2
0
        public IEntityList FindMany(IFinder finder, int Page, int PageSize)
        {
#if DEBUG
            Stopwatch sw = new Stopwatch();
            sw.Start();
#endif
            IEntityList  result = CreateObjectList();
            PagedDataSet ds     = GetPagedDataSet(finder, Page, PageSize);
            result.PagingInfo = ds.PagingInfo;

            foreach (DataRow row in ds.Tables[0].Rows)
            {
                result.Add(ReadRow(new RowReader(row)));
            }

#if DEBUG
            sw.Stop();
            LogMessage("FindMany+1", finder.FindCommand, sw.ElapsedMilliseconds);
#endif
            return(result);
        }