Telerik OpenAccess Classic

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

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.

Suppose you have the following code: 

C# Copy Code
[Persistent]
class Group
 {
    
public string name;
    
public IList<Element> elements;
    Group(
string n)
    {
       name = n;
       elements =
new List<Element>();
    }
}
[Persistent]
class Element
{
    
public string name;
    
public IList<Group> groups;
    Element(
string n)
    {
       name = n;
       groups =
new List<Group>();
    }
}
static void SampleData()
{
    
// Sample Data
    
scope.Transaction.Begin();
    Group g1 =
new Group("g1");
    g1.elements.Add(
new Element("e1"));
    scope.Add(l_table1);
    scope.Transaction.Commit();
}

The following query "Q1" will return all Group instances, where the name of the elements of the referenced elements is "e1", or where an element references a group named "g1":

OQL Copy Code
"SELECT * FROM GroupExtent AS g, g.elements AS e
WHERE e.NAME=\"e1\" OR EXISTS x IN e.groups : (x.name=\"g1\");  
The parenthesis at the end, states the scope of the x variable explicitly, and this might be necessary in cases where a more complex condition is required.

However, a chain of iterators (g,e,x) can also be defined like in "Q2":

OQL Copy Code
"SELECT * FROM GroupExtent AS g, g.elements AS e, e.groups AS x
WHERE e.NAME=\"e1\" OR x.name=\"g1\";

The semantic here is, that at least one "x" must exist for the "g" to be included in the result set evaluation (where clause), i.e., the evaluation will not include the chain's start instances, which have an empty collection along the path to the last declared iterator. Therefore, the above two queries, "Q1" and "Q2" demonstrate the subtle difference between the semantics of the iterator declarations and the "exists" keyword. The exists keyword does allow objects with empty collections to be tested; the iterator chain will require at least one element in the collection to be present (refer to The EXISTS Keyword topic for more information).

See Also