public static Task <List <T> > ExecuteReaderAsync <T>(this ISqlConnectionController @this, SqlCommand cmd, Func <SqlDataRow, T?> builder, CancellationToken cancellationToken = default) where T : notnull { async Task <List <T> > ReadRowsAsync(SqlCommand c, CancellationToken t) { var collector = new List <T>(); using (var r = await c.ExecuteReaderAsync(t).ConfigureAwait(false)) { var row = new SqlDataRow(r); while (await r.ReadAsync(t).ConfigureAwait(false)) { var o = builder(row); if (o is not null) { collector.Add(o); } } } return(collector); } return(ExecuteQueryAsync(@this, cmd, ReadRowsAsync, cancellationToken)); }
public static List <T> ExecuteReader <T>(this ISqlConnectionController @this, SqlCommand cmd, Func <SqlDataRow, T?> builder) where T : notnull { List <T> ReadRows(SqlCommand c) { var collector = new List <T>(); using (var r = c.ExecuteReader()) { var row = new SqlDataRow(r); while (r.Read()) { var o = builder(row); if (o is not null) { collector.Add(o); } } } return(collector); } return(ExecuteQuery(@this, cmd, ReadRows)); }