Sql.Net Class Library Documentation

SelectQuery Class

Encapsulates a SQL SELECT statement.

For a list of all members of this type, see SelectQuery Members.


public class SelectQuery : ICloneable

Thread Safety

Public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe.


Use SelectQuery to define and modify a query. When the query is ready to be executed it can be rendered to SQL using one of the renderers derived from ISqlOMRenderer and executed using standard .Net query execution methods.

SelectQuery can be useful for dynamic SQL generation for reports and filters.

It can also be used to render SQL to retrieve pages of data from databases which do not directly support this feature (i.e. SqlServer).


The following example creates a select query which returns two columns from two inner joined tables and renders it to be executed on MySql

FromTerm tCustomers = FromTerm.Table("customers");
FromTerm tProducts = FromTerm.Table("products", "p");
FromTerm tOrders = FromTerm.Table("orders", "o");

SelectQuery query = new SelectQuery();
query.Columns.Add(new SelectColumn("name", tCustomers));
query.Columns.Add(new SelectColumn("name", tProducts));
query.FromClause.BaseTable = tCustomers;
query.FromClause.Join(JoinType.Inner, query.FromClause.BaseTable, tOrders, "customerId", "customerId");
query.FromClause.Join(JoinType.Inner, tOrders, tProducts, "productId", "productId");

MySqlRenderer renderer = new MySqlRenderer();
   string sql = renderer.RenderSelect(query);
This example creates a select query which returns the second page of a result-set and renders it to be executed on SqlServer
int totalRows = 50; //The total number of rows can be obtained using SelectQuery as well

SelectQuery query = new SelectQuery();

query.Columns.Add(new SelectColumn("name"));
query.FromPhrase.BaseTable = FromClause.Table("customers");
query.OrderByClauses.Add(new OrderByClause("name", null, OrderByDirection.Descending));
query.OrderByClauses.Add(new OrderByClause("birthDate", null, OrderByDirection.Ascending));

SqlServerRenderer renderer = new SqlServerRenderer();
   sql = renderer.RenderPage(2, 10, totalRows, query);


Namespace: Reeb.SqlOM

Assembly: Reeb.SqlOM (in Reeb.SqlOM.dll)

See Also

SelectQuery Members | Reeb.SqlOM Namespace