コード例 #1
0
        /// <summary>
        /// Multi-ResultSet일 경우에 DataTable 컬렉션으로 반환합니다.
        /// </summary>
        public static Task <IList <DataTable> > ExecuteDataTableAsListAsync(this NpgsqlDatabase db,
                                                                            NpgsqlCommand cmd,
                                                                            int firstResult,
                                                                            int maxResults,
                                                                            params IAdoParameter[] parameters)
        {
            cmd.ShouldNotBeNull("cmd");
            firstResult.ShouldBePositiveOrZero("firstResult");
            maxResults.ShouldBePositiveOrZero("maxResults");

            if (IsDebugEnabled)
            {
                log.Debug(
                    "비동기 방식으로 ExecuteDataTableAsListAsync을 실행합니다... CommandText=[{0}], firstResult=[{1}], maxResults=[{2}], Parameters=[{3}]",
                    cmd.CommandText, firstResult, maxResults, parameters.CollectionToString());
            }

            return
                (ExecuteReaderAsync(db, cmd, parameters)
                 .ContinueWith(task => {
                IList <DataTable> tables = new List <DataTable>();

                using (var reader = task.Result)
                    using (var adapter = new AdoDataAdapter(db.GetDataAdapter())) {
                        do
                        {
                            var dataTable = new DataTable {
                                Locale = CultureInfo.InvariantCulture
                            };
                            adapter.Fill(new[] { dataTable }, reader, firstResult, maxResults);

                            if (IsDebugEnabled)
                            {
                                log.Debug("비동기 방식으로 DataReader를 가져와 DataTable에 Load 했습니다!!!");
                            }

                            tables.Add(dataTable);
                        } while(reader.IsClosed == false && reader.NextResult());
                    }

                return tables;
            },
                               TaskContinuationOptions.ExecuteSynchronously));
        }