コード例 #1
0
 /// <summary>
 /// Converts the <see cref="DbDataReader"/> into an enumerable of data entity objects.
 /// </summary>
 /// <typeparam name="TResult">The type of the result.</typeparam>
 /// <param name="reader">The <see cref="DbDataReader"/> to be converted.</param>
 /// <param name="dbFields">The list of the <see cref="DbField"/> objects to be used.</param>
 /// <param name="dbSetting">The instance of <see cref="IDbSetting"/> object to be used.</param>
 /// <returns>A list of the target result type.</returns>
 public static IEnumerable <TResult> ToEnumerable <TResult>(DbDataReader reader,
                                                            IEnumerable <DbField> dbFields = null,
                                                            IDbSetting dbSetting           = null)
 {
     if (reader?.IsClosed == false && reader.HasRows)
     {
         var func = FunctionCache.GetDataReaderToTypeCompiledFunction <TResult>(reader,
                                                                                dbFields,
                                                                                dbSetting);
         while (reader.Read())
         {
             yield return(func(reader));
         }
     }
 }
コード例 #2
0
        /// <summary>
        /// Converts the <see cref="DbDataReader"/> into an enumerable of data entity objects in asynchronous way.
        /// </summary>
        /// <typeparam name="TResult">The type of the result.</typeparam>
        /// <param name="reader">The <see cref="DbDataReader"/> to be converted.</param>
        /// <param name="dbFields">The list of the <see cref="DbField"/> objects to be used.</param>
        /// <param name="dbSetting">The instance of <see cref="IDbSetting"/> object to be used.</param>
        /// <param name="cancellationToken">The <see cref="CancellationToken"/> object to be used during the asynchronous operation.</param>
        /// <returns>A list of the target result type.</returns>
        public static async IAsyncEnumerable <TResult> ToEnumerableAsync <TResult>(DbDataReader reader,
                                                                                   IEnumerable <DbField> dbFields = null,
                                                                                   IDbSetting dbSetting           = null,
                                                                                   [EnumeratorCancellation] CancellationToken cancellationToken = default)
        {
            if (reader?.IsClosed != false || !reader.HasRows)
            {
                yield break;
            }

            var func = FunctionCache.GetDataReaderToTypeCompiledFunction <TResult>(reader,
                                                                                   dbFields,
                                                                                   dbSetting);

            while (await reader.ReadAsync(cancellationToken))
            {
                yield return(func(reader));
            }
        }
コード例 #3
0
ファイル: DataReader.cs プロジェクト: wanglin2019/RepoDB
        /// <summary>
        /// Converts the <see cref="DbDataReader"/> into an enumerable of data entity objects in asynchronous way.
        /// </summary>
        /// <typeparam name="TResult">The type of the result.</typeparam>
        /// <param name="reader">The <see cref="DbDataReader"/> to be converted.</param>
        /// <param name="dbFields">The list of the <see cref="DbField"/> objects to be used.</param>
        /// <param name="dbSetting">The instance of <see cref="IDbSetting"/> object to be used.</param>
        /// <param name="cancellationToken">The <see cref="CancellationToken"/> object to be used during the asynchronous operation.</param>
        /// <returns>A list of the target result type.</returns>
        public static async Task <IEnumerable <TResult> > ToEnumerableAsync <TResult>(DbDataReader reader,
                                                                                      IEnumerable <DbField> dbFields      = null,
                                                                                      IDbSetting dbSetting                = null,
                                                                                      CancellationToken cancellationToken = default)
        {
            var list = new List <TResult>();

            if (reader != null && reader.IsClosed == false && reader.HasRows)
            {
                var func = FunctionCache.GetDataReaderToTypeCompiledFunction <TResult>(reader,
                                                                                       dbFields,
                                                                                       dbSetting);
                while (await reader.ReadAsync(cancellationToken))
                {
                    list.Add(func(reader));
                }
            }
            return(list);
        }