Telerik OpenAccess Classic

Telerik OpenAccess ORM Send comments on this topic.
Querying on Object Identity
See Also
Programmer's Guide > OpenAccess ORM Classic (Old API) > Telerik OpenAccess ORM OQL Reference > OQL - Object Query Language > Querying on Object Identity

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.

You can query for a reference to a specific object by using a parameter. OQL provides this capability using the tokens $1, $2, etc, to identify parameters in the OQL query string:

OQL Copy Code
SELECT p FROM PersonExtent AS p
WHERE p.mother = $1

Within the query expression the tokens ($1, $2....) are placeholders for the parameter values. The actual parameter values are passed in the Execute() method as an array of objects. The tokens are substituted by the values when the query expression is parsed; the first parameter is bound to $1, the second to $2, and so forth. The parameter $1 can be null or a persistence capable object of a database or the object id of a persistence capable object.

The following is a partial listing of an example Person class, which has a reference to a Address class:

C# Copy Code
class Person {
  
// . . .
  
Address address;
  
string firstName;
  
// . . .
}
;
class Address {
  
// . . .
  
string streetName;
  
int pinCode;
  
// . . .
}
;
C# Copy Code
getPerson (IObjectScope scope, IObjectId addressId)
{
string queryString = "SELECT * FROM PersonExtent AS p" +
  
"WHERE p.address = $1";
IQuery oqlQuery = scope.GetOqlQuery(queryString);
IQueryResult result = oqlQuery.Execute(addressId);
// . . .
}
;
VB.NET Copy Code
Sub New(scope As IObjectScope, addressId As IObjectId)
 Dim queryString As String = "SELECT * FROM PersonExtent AS p WHERE p.address = $1"
 Dim oqlQuery As IQuery = scope.GetOqlQuery(queryString)
 Dim result As IQueryResult = oqlQuery.Execute(addressId)
End Sub

The above query contains an identity comparison where, p.address equals addressId. The object identifier of addressId is passed as a parameter. This query will return all Person objects whose address reference has an id equal to the addressid.  

See Also