Method BindColumn
- Namespace
- YndigoBlue.Velocity.Engine
- Assembly
- YndigoBlue.Velocity.dll
BindColumn<T>(string)
Binds a single column from query results to a typed enumerable collection by column name.
public IEnumerable<T> BindColumn<T>(string columnName)
Parameters
columnNamestringThe name of the column to bind.
Returns
- IEnumerable<T>
A lazy IEnumerable<T> that streams typed values from the specified column one row at a time.
Type Parameters
TThe type to bind the column values to.
Examples
var conn = new SqlServerDatasourceConnection
{
Hostname = "localhost",
Database = "sales_db",
Username = "sa",
Password = "password"
};
using (var manager = new Manager(conn))
{
var schema = manager.LoadSchema("dbo");
var ordersTable = schema["orders"];
var query = new Query()
.Select([ordersTable["order_total"]])
.From(ordersTable)
.Where(new Criterion<DateTime>(ordersTable["order_date"], ConditionalType.GreaterThan, DateTime.Today.AddDays(-30)));
using (ResultReader reader = manager.ExecuteReader(query))
{
// Extract just the order_total column as decimals
foreach (decimal total in reader.BindColumn<decimal>("order_total"))
{
Console.WriteLine($"Order total: {total:C}");
}
}
}
Remarks
Returns a lazy enumerable backed by yield return. The returned sequence reads from the live database
reader and must be iterated inside the enclosing using (ResultReader ...) block.
Iterating after the reader has been disposed will throw.
BindColumn<T>(int)
Binds a single column from query results to a typed enumerable collection by column index.
public IEnumerable<T> BindColumn<T>(int columnIndex)
Parameters
columnIndexintThe zero-based index of the column to bind.
Returns
- IEnumerable<T>
A lazy IEnumerable<T> that streams typed values from the specified column one row at a time.
Type Parameters
TThe type to bind the column values to.
Remarks
Returns a lazy enumerable backed by yield return. The returned sequence reads from the live database
reader and must be iterated inside the enclosing using (ResultReader ...) block.
Iterating after the reader has been disposed will throw.
BindColumn<T>()
Binds the first column from query results to a typed enumerable collection.
public IEnumerable<T> BindColumn<T>()
Returns
- IEnumerable<T>
A lazy IEnumerable<T> that streams typed values from the first column one row at a time.
Type Parameters
TThe type to bind the column values to.
Remarks
Returns a lazy enumerable backed by yield return. The returned sequence reads from the live database
reader and must be iterated inside the enclosing using (ResultReader ...) block.
Iterating after the reader has been disposed will throw.