Method Search
- Namespace
- YndigoBlue.Velocity.Engine
- Assembly
- YndigoBlue.Velocity.dll
Search(Query)
Executes a query and returns a forward-only, connected data reader for iterating through results.
public ResultReader Search(Query query)
Parameters
Returns
- ResultReader
A ResultReader that provides forward-only access to query results while maintaining an open database connection.
Examples
using (var m = new Manager(conn))
{
var schema = m.LoadSchema("app");
var usersTable = schema["users"];
var query = new Query()
.Select([usersTable["name"], usersTable["email"]])
.From(usersTable)
.Where(new Criterion<bool>(usersTable["active"], ConditionalType.Equals, true));
// Always wrap ResultReader in a using block.
// Consume BindResults / BindColumn inside the using — iterating after disposal will throw.
using (ResultReader reader = m.Search(query))
{
foreach (User user in reader.BindResults<User>(BindingType.SnakeCase))
{
Console.WriteLine($"{user.Name}: {user.Email}");
}
}
}
Remarks
Caller must dispose — always wrap in a using block. The ResultReader holds
an open database connection and an active DbDataReader; failing to dispose it will
leak both resources.
Lazy enumeration — consume inside the using block.
BindResults<T>(BindingType) and BindColumn<T>(string)
(and their overloads) return lazy IEnumerable<T> sequences backed by yield return.
The sequence reads from the live database reader one row at a time. If you store the enumerable and iterate it
after the using block has closed, the underlying reader will already be disposed and the iteration will throw.
Use Search for large result sets to avoid loading all data into memory. The connection remains open while iterating. Use Retrieve(Query) instead when you need in-memory random access or the ability to bind the same results to multiple types.
Exceptions
- DbException
Thrown when a database error occurs.