/// <summary> /// Creates an enumerable list of instances of the specified type create from /// a data reader. /// </summary> /// <typeparam name="T"> /// The data object type. This should be a class with properties matching the reader /// value. /// </typeparam> /// <param name="reader">An open reader ready to be read to a list.</param> /// <returns>An enumerable list of instances of type 'T' created from the data reader.</returns> public static IEnumerable <T> ReadData <T>(this DbDataReader reader) { if (reader == null) { throw new ArgumentNullException("reader"); } var result = new List <T>(); if (EntityMapping.IsSimpleType <T>()) { while (reader.Read()) { result.Add(EntityMapping.ReadHelper.Get <T>(reader, 0)); } } else { var map = EntityMapping.MapDbReaderColumns(reader); var readEntity = EntityMapping.GetEntityFunc <T>(); while (reader.Read()) { result.Add(readEntity(reader, map)); } } return(result); }
public ResultStreamEnumerator(IContext context, SqlCommandManager manager) { _isSimpleType = EntityMapping.IsSimpleType <T>(); _readEntity = _isSimpleType ? GetSimple : EntityMapping.GetEntityFunc <T>(); _connection = AsyncHelper.RunSync(() => manager.CreateConnectionAsync()); _command = _connection.CreateCommand(); _command.Connection = _connection; _command.CommandText = context.CommandText; manager.AddParametersToCommand(_command, context); _connection.Open(); _reader = _command.ExecuteReader(); _map = _isSimpleType ? null : EntityMapping.MapDbReaderColumns(_reader); }