Telerik OpenAccess Classic

Telerik OpenAccess ORM Send comments on this topic.
Fetch Groups
Programmer's Guide > OpenAccess ORM Classic (Old API) > Programming With OpenAccess > Mapping > Fetch Groups

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.

Fetch groups represent a grouping of fields that are retrieved from the datastore together. They can be used to optimize the runtime behavior while accessing objects in known patterns.

Currently, if you write:

Copy Code
SELECT p FROM EmployeeExtent AS p

All the fetched objects will be "hollow" and therefore they will contain no values. Only the id will be fetched from the server. This means that in the first server call no values of the default FetchGroup are retrieved and a second server call will need to be made for every accessed object.

However if you write:

Copy Code
SELECT * FROM EmployeeExtent

All the fetched objects are filled with the values of the default fetchgroup, during the first server call itself. This means that when the user accesses the object no separate SQL call is needed.

Due to the behavior described above, it is better, in most cases, to use "SELECT *..." for performance reasons. Though, there are some cases, where it would be better to use "SELECT p...", for e.g., in those case where retrieving all the values could be a memory burden. Assume you have a class with 200 string members, all of them would get loaded. When a big result set is retrieved, this could make a difference in the memory consumption. However in most cases, we recommend the usage of the "SELECT *..." syntax.

The usage of the "SELECT *..." syntax is recommended, in most cases.

In the future we will change and improve fetching rows, and the behavior of "SELECT p..." might change.

OpenAccess ORM supports multiple fetch groups per class for precise control over which fields are fetched and how they are fetched. FetchGroups can be used in combination with the FetchGroupCollector (refer to The FetchGroup Collector for more information). The FetchGroupCollector allows you to collect all objects that are recursively reachable from a set of root objects through the fields of the specified fetch group.

It is also be possible to specify a FetchGroup when executing a query or loading the complete fetch group of an object (refer to FetchGroups for more information).

PostLoad() is called after the default fetch group values are loaded in the persistent instance. This is not done inside the query execution. The fields are loaded into the instance, either when you access a default fetch group field or when you call retrieve(). Inside the PostLoad call, only fields of the default fetch group are allowed to be accessed; other fields may not be set. It is only allowed to change transient fields from within the PostLoad, for e.g., Overriding PostLoad() is useful for initializing transient fields.

The FetchGroup Collector

The FetchGroupCollector calculates the object graph, starting from the "root object" specified in the Collect method. Fetchgroups are used to specify which object members will be loaded while resolving the object graph. Since the ObjectContainer only contains complete objects, the collector only specifies the references to be followed for copying a tree into the container.

The FetchGroupCollector had three predefined values:

Deep FetchGroup

Default FetchGroup

Depend FetchGroup

Deep FetchGroup

This is used to specify that the "Deep" fetchgroup is to be used in the Collect method. The "Deep" fetchgroup specifies that while copying an object to the ObjectContainer, all objects referenced from this given object will also be copied to the ObjectContainer. This algorithm is applied recursively.

For e.g., the following shows the use of the fg_orderNo_linesWithProduct with a FetchGroupCollector (DeepFetchgroup):

Copy Code
FetchGroupCollector fg =
  new FetchGroupCollector( FetchGroupCollector.DeepFetchGroup, "fg_orderNo_linesWithProduct");
Order order = . . . ;
IEnumerable result = fg.Calculate( order );

The result will contain the Order instance, order, and all referenced OrderLine instances including the Product instances they reference.

Default FetchGroup

This is used to specify that the "Default" fetchgroup is to be used in the Collect method. The "Default" fetchgroup specifies that all the fields in the "Default" fetchgroup will be loaded, while copying an object to the ObjectContainer (refer Default FetchGroup to for more information).

Depend FetchGroup

This is used to specify that the "Depend" fetchgroup is to be used in the Collect method. The "Depend" fetchgroup specifies that while copying an object to the ObjectContainer, only members that have the DependAttribute specified will be loaded (refer to Dependent References / Cascading Deletes for more information). This algorithm is applied recursively.

User Defined FetchGroup

In addition to the predefined fetchgroups, user defined fetchgroups can also be used. The "User defined" fetchgroup specifies that while copying an object to the ObjectContainer, only members that have been specified in the fetchgroup will be loaded (refer to FetchGroups for more information).