Class ResultReader
- Namespace
- YndigoBlue.Velocity.Engine
- Assembly
- YndigoBlue.Velocity.dll
Provides forward-only, read-once iteration over query results with minimal memory overhead.
public class ResultReader : IEnumerable<Result>, IEnumerable, IDisposable
- Inheritance
-
ResultReader
- Implements
Examples
var conn = new PostgreSqlDatasourceConnection
{
Hostname = "localhost",
Database = "mydatabase",
Username = "user",
Password = "password"
};
using (var manager = new Manager(conn))
{
var schema = manager.LoadSchema("public");
var usersTable = schema["users"];
var query = new Query()
.Select([usersTable["id"], usersTable["name"], usersTable["email"]])
.From(usersTable)
.Where(new Criterion<bool>(usersTable["active"], ConditionalType.Equals, true));
// Use ResultReader for large datasets
using (ResultReader reader = manager.ExecuteReader(query))
{
foreach (Result row in reader)
{
int id = row.GetFieldInteger("id");
string name = row.GetFieldVarChar("name");
string email = row.GetFieldVarChar("email");
Console.WriteLine($"{id}: {name} ({email})");
}
} // Reader and connection are disposed here
}
Remarks
ResultReader is a connected, streaming result processor that wraps a database reader for efficient memory usage when processing large result sets. Unlike ResultSet which loads all results into memory, ResultReader processes rows one at a time as they're retrieved from the database.
Key Characteristics:
- Forward-only iteration - cannot go backwards or re-read results
- Minimal memory footprint - only one row in memory at a time
- Requires active database connection during iteration
- Must be disposed to release database resources
- Ideal for processing large datasets or streaming operations
When to Use:
- Processing large result sets where memory is a concern
- Streaming data transformations or exports
- Sequential processing where random access isn't needed
- Real-time data processing or ETL operations
Use ResultSet instead when:
- Need random access to results (indexing)
- Need to iterate multiple times
- Need to filter or sort results in memory
- Result set is small enough to fit in memory
Methods
- BindColumn<T>()
Binds the first column from query results to a typed enumerable collection.
- BindColumn<T>(int)
Binds a single column from query results to a typed enumerable collection by column index.
- BindColumn<T>(string)
Binds a single column from query results to a typed enumerable collection by column name.
- BindResults<T>(BindingType)
Binds query results to a typed enumerable collection using the specified binding strategy.
- Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
- GetEnumerator()
Returns an enumerator that iterates through the collection.
- GetGeoJSON(string, bool)
Converts query results containing geospatial data to GeoJSON format.