Telerik OpenAccess Classic

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

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.

The EXISTS keyword is used to test whether a query condition is true for a single object in a collection. The statement returns true even if only one element within the collection satisfies the query condition(s). If no objects are found that meet the conditions, the statement returns false.

OQL Copy Code
SELECT * FROM EmployeeExtent AS emp  WHERE EXISTS tr IN emp.employeeTerritories : (tr.Region.RegionDescription like "Eas**")

The EXISTS in the above example will return those employees which came from regions whose territory description starts with "Eas".

Finding Objects Not Contained in a Collection

Suppose we have the following model:

C# Copy Code
[Persistent]
class Person
{
   
private IList<Address> addresses = new List<Address>();
   
private string name;
   
public string Name
   {
       get {
return name; }
       set { name = value; }
   }
   
public IList<Address> Addresses
   {
       get {
return addresses; }
       set { addresses = value; }
   }
}
C# Copy Code
[Persistent]
class Address
{
   
private string city;
   
public string City
   {
       get {
return city; }
       set { city = value; }
   }
}

As seen in the above model, the Person class has a collection of Addresses. Now, if you want to find all Persons without an address in "Munich", the following query can be used:

OQL Copy Code
SELECT * FROM PersonExtent AS person
WHERE NOT (EXISTS address IN person.addresses : address.city LIKE 'Munich')

You can also write the same query using a string parameter as shown below:

OQL Copy Code
SELECT * FROM PersonExtent AS person
WHERE NOT (EXISTS address IN person.addresses : address.city LIKE $1)

Or with an address object as shown below:

OQL Copy Code
SELECT * FROM PersonExtent AS person
WHERE NOT (EXISTS address IN person.addresses : address = $1)

See Also