Telerik OpenAccess Classic

Telerik OpenAccess ORM Send comments on this topic.
Forwards Only Versus Random Access Query Results
See Also
Programmer's Guide > OpenAccess ORM Classic (Old API) > Telerik OpenAccess ORM OQL Reference > OQL - Object Query Language > Forwards Only Versus Random Access Query Results

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 IQuery.ForwardsOnly property determines how the query result can be accessed. Specifically, whether random access to query results is allowed or not. By default, the query result can be accessed "forwards only".

"Forwards Only" Behavior

If you are using Telerik OpenAccess ORM with ForwardsOnly = true (the default), you will see the following behavior. If you get an enumerator from the query result and get new instances by calling MoveNext() OpenAccess keeps the result set open and rows are fetched in batches as needed (the number of rows fetched in each batch is configurable using the Prefetch property). This works well if you only want the first few results. The instances are only created when you ask for them. If you use the IList interface of the query result and call Get( index ), OpenAccess will efficiently skip rows to arrive at the index. However, the index must be greater than or equal to the previously highest requested index.

If you call Count() on the query result OpenAccess assumes you want all the results and will retrieve them in one call and close the result set. The results are stored for random access. You can then use the IList interface without any restrictions. For example, you can call the Get() method with an arbitrary index parameter. This also means that you can also create an ArrayList a = new ArrayList(q.execute()).

With a forward result set you can call Count() as the first action and everything will be resolved in one call or you can iterate, but it will not work if you start iterating and then call Count().

Random Access Behavior

If you are using OpenAccess with ForwardsOnly = false (i.e., Random Access), you can use the IList interface without any restrictions. For example, you can call the Get() method with an arbitrary index parameter. You can also call Count() without resolving the entire list. OpenAccess must use a scrollable result set to provide this functionality. This may use more database resources (cursors etc.) than a normal forwards only result set. This option is useful for paged results, i.e., you only want a few results from position n onwards.

See Also