Telerik OpenAccess Classic

Telerik OpenAccess ORM Send comments on this topic.
Overview
Programmer's Guide > OpenAccess ORM Classic (Old API) > Telerik OpenAccess ORM OQL Reference > OQL - Object Query Language > The WHERE Clause > Overview

Glossary Item Box

This documentation article is a legacy resource describing the functionality of the deprecated OpenAccess Classic only. The contemporary documentation of Telerik OpenAccess ORM is available here.

Use the WHERE clause to specify the search conditions (shown in the preceding example as the compare-predicate of a query). The search conditions consist of SQL-like comparison strings, comparing class member values and literal constants. The literal constants may be any valid OpenAccess base type. The literals are type-checked and must be of the same type as the class member. The compare-predicate is a boolean predicate because it always evaluates to either true or false. The boolean operators AND and OR can be used to construct arbitrarily complex conditions. Usage of the WHERE clause is optional, i.e., when a WHERE clause is not specified, the complete extent will be returned.In the following example, the WHERE clause limits, or filters, the result-set to all objects in the extent that have a Freight value greater than 100:

OQL Copy Code
SELECT *
FROM OrderExtent AS ord
WHERE ord.Freight > 100

The above query will find all orders that have freight more than 100. Public properties can be used in OQL expressions with the help of the FieldAlias attribute. The FieldAlias attribute marks the property as an alias for a given field. Whenever the query parser encounters a property in an OQL query, it uses the corresponding field that has been specified in the FieldAlias attribute (refer to The Alias Property topic for more information). The FieldAlias attribute is added as shown below:

C# Copy Code
[Persistent]
class Order {
private decimal Freight;
....
[FieldAlias(
"freight")]
public decimal Freight{
 get {
return freight; }
 set { freight = value; }
}
}

After adding the FieldAlias attribute, it is now possible to use the Freight property as an alias for the freight field in queries. For example:

OQL Copy Code
SELECT *
FROM OrderExtent AS ord
WHERE ord.Freight > 100

The above query will find all orders that have freight more than 100.

Querying a Collection Type Field

The scenario for the example is explained below. you have 2 classes: Employee and Employee Territory. Employee has a many-to-many relationship with Employee Territory. Now, if we need to retrieve the Employee having Boston as territory, the following query will be used:

OQL Copy Code
SELECT *
FROM EmployeeExtent AS p, p.EmployeeTerritories AS o
WHERE o.TerritoryDescription="Boston"

The "o" variable is used to traverse the EmployeeTerritory collection.

In this section: