Telerik OpenAccess Classic

Telerik OpenAccess ORM Send comments on this topic.
Result Sets
See Also
Programmer's Guide > OpenAccess ORM Classic (Old API) > Telerik OpenAccess ORM OQL Reference > OQL - Object Query Language > The Select Statement > Result Sets

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.

A query returns a set of objects known as the result-set. The elements of a result-set are specified in the main clause of the SELECT statement (immediately following the SELECT keyword). The result-set elements are either of the same type as the set-variable defined in the FROM clause or that of a data-member determined by a path-expression rooted to the set-variable (refer to  Overviewtopic for more information). OpenAccess supports two methods for specifying selection members:

  • All members of the queried set or the extent (* option, or set-variable).
  • A specific member of the queried set or extent (set-variable.member or path-expression).

In the first method, the result-set variable is the same as the set-variable specified in the FROM statement. This means that the type of the objects that are being queried is of the same object type that you want to see in the result-set. In the second method, the result-set element type is that of the data-member on the right-hand side of the path-expression. Compare the following examples:

Example 1:

OQL Copy Code
SELECT *

The type of the result-set elements is the same as the type of the set-variable. The set-variable is defined in the FROM clause:

OQL Copy Code
FROM OrderExtent AS order

The set-variable (order) is of type Order.

Example 2:

OQL Copy Code
SELECT order

Here, again, the set-variable is of the same type as that of the result-set elements:

OQL Copy Code
FROM order IN OrderExtent

The result-set is of type Order.

Example 3: 

OQL Copy Code
SELECT order.ShipCity

The type of the result-set elements is the same as the type of the ShipCity data-member. (Again, the set-variable is defined in the FROM clause):

OQL Copy Code
FROM OrderExtent AS order

The set-variable type is Order and the class must define a data-member named ShipCity(which is a string in the Northwind database). These forms are explained in detail later. (Also, refer to the Extents and Overview topics.)

Selecting All Members

The (*) option of the SELECT statement selects all members of a class:

OQL Copy Code
SELECT * FROM OrderExtent
WHERE ShipCity = 'Lyon'

By stating (*), every member of the queried set is selected and returned in the result-set. Similarly, you may specify the extent or set a variable instead of the (*) option:

OQL Copy Code
SELECT order FROM OrderExtent AS order
WHERE order.ShipCity = "Lyon"

The use of an extent-variable, in the above case product, also selects all members for the result-set. Here is an example of executing the above query and displaying the selected city and the order ID from which it is.

C# Copy Code
IObjectScope scope =OpenAccessData.ObjectScopeProvider1.GetNewObjectScope();
string query = "SELECT * FROM OrderExtent WHERE ShipCity='Lyon'";
var result = scope.GetOqlQuery(query).Execute();
foreach (OpenAccessData.Order ord in result)
{
Console.WriteLine(ord.ShipCity+
" "+ ord.OrderID);
}
VB.NET Copy Code
Dim scope As IObjectScope = OpenAccessData.ObjectScopeProvider1.GetNewObjectScope()
Dim query As String = "SELECT * FROM OrderExtent WHERE ShipCity='Lyon'"
Dim result As var = scope.GetOqlQuery(query).Execute()
For Each ord As OpenAccessData.Order In result
 Console.WriteLine(ord.ShipCity + " " + ord.OrderID)
Next

Selecting All Instances of a Member of an Extent

By using a path expression, you can direct the result-set to be a set of members of a set-variable. The following query returns a set of string objects (the Ship cities of all products in the database):

OQL Copy Code
SELECT ord.ShipCity
FROM OrderExtent AS ord

The result-set is an IQueryResult instance that contains string elements. What this means in practice is that your query need not return a result-set of persistent objects. For example, if the member is of type decimal the result-set will be a set of float values. The following query returns a result-set of decimal values containing all Order.Freight values in the database:

OQL Copy Code
SELECT ord.Freight
FROM OrderExtent AS ord

This query returns an OpenAccess.IQueryResult instance that contains decimal values representing the Freight values for all orders in the database. In the preceding examples, you could specify a data-member of the set-variable (e.g., product.unitPrice) in order to select the members into the result-set. Selecting a list of members (i.e., multiple members) can be done as the following example shows:

OQL Copy Code
SELECT ord.OrderID, ord.ShipCity
FROM OrderExtent AS ord
In the above query you are retrieving several members. You can access them later as an array of objects. Each "row" in the result set will contain array of objects representing the selected members.

This is an example of how you can retrieve multiple members from a table and access them after.

C# Copy Code
IObjectScope scope =OpenAccessData.ObjectScopeProvider1.GetNewObjectScope();
string query = "SELECT ord.OrderID, ord.ShipCity FROM OrderExtent as ord";
var result = scope.GetOqlQuery(query).Execute();
foreach (object[] ord in result)
{
Console.WriteLine(ord[0]+
" "+ord[1]);
}
VB.NET Copy Code
Dim scope As IObjectScope = OpenAccessData.ObjectScopeProvider1.GetNewObjectScope()
Dim query As String = "SELECT ord.OrderID, ord.ShipCity FROM OrderExtent as ord"
Dim result As var = scope.GetOqlQuery(query).Execute()
For Each ord As Object() In result
 Console.WriteLine(ord(0) + " " + ord(1))
Next

Filtering — The WHERE Clause

Most examples in this section selected all elements of the extent and placed them in the result-set. The actual number of objects that are selected and placed into the result-set is also dependent on the WHERE clause. If the WHERE clause is omitted, every object in the input set is selected. By providing query criteria in the WHERE clause, you can select only specific objects whose attribute values meet a specified criteria:

OQL Copy Code
...
WHERE ord.ShipCity = "Lyon"
...

For more information, please refer to the Where Clause section.

Additional Notes Regarding Result Sets

The result does not necessarily contain accessible or even valid object references. The query optimizer makes every attempt to choose the best possible query execution plan. Depending on the actual choices made by the optimizer, an object in the result-set may or may not be accessible due to locking, user authorization, etc. It is also possible that a reference to an already deleted object may be returned depending on whether the query made its choices based on objects in local memory.

See Also