Method BindColumn
- Namespace
- YndigoBlue.Velocity.Engine
- Assembly
- YndigoBlue.Velocity.dll
BindColumn<T>(string)
Binds a single column from query results to a typed list by column name.
public IList<T> BindColumn<T>(string columnName)
Parameters
columnNamestringThe name of the column to bind.
Returns
- IList<T>
A list of typed values from the specified column.
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_id"], ordersTable["order_total"]])
.From(ordersTable);
ResultSet results = manager.ExecuteResultSet(query);
// Extract just the order_total column as a list of decimals
IList<decimal> totals = results.BindColumn<decimal>("order_total");
decimal sum = totals.Sum();
Console.WriteLine($"Total revenue: {sum:C}");
results.Dispose();
}
BindColumn<T>(int)
Binds a single column from query results to a typed list by column index.
public IList<T> BindColumn<T>(int columnIndex)
Parameters
columnIndexintThe zero-based index of the column to bind.
Returns
- IList<T>
A list of typed values from the specified column.
Type Parameters
TThe type to bind the column values to.
BindColumn<T>()
Binds the first column from query results to a typed list.
public IList<T> BindColumn<T>()
Returns
- IList<T>
A list of typed values from the first column.
Type Parameters
TThe type to bind the column values to.