Select

public static IEnumerable<T> Select<T>(this SqlDataReader reader, Func<SqlDataReader, T> projection)
{
   while (reader.Read())
   {
      yield return projection(reader);
   }
}
Example:
using (DataReader reader = ...)
{
    List<Customer> customers = reader.Select(r => new Customer {
        CustomerId = r["id"] is DBNull ? null : r["id"].ToString(),
        CustomerName = r["name"] is DBNull ? null : r["name"].ToString() 
    }).ToList();
}

Description

It returns reader lines which can be retrieved from lamba statement

Details

Double click on the code to select all.

 

;