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.