Telerik OpenAccess Classic

Telerik OpenAccess ORM Send comments on this topic.
How to: Execute a Query that Returns Specific Persistent Type
Programmer's Guide > OpenAccess ORM Classic (Old API) > OpenAccess Tasks > Querying a Data Model > How to: Execute a Query that Returns Specific Persistent Type

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.

This article is focused on retrieving objects from specific persistent-capable types.

Telerik OpenAccess ORM Q1 2010 Release comes with several new or renamed assemblies:

  • Telerik.OpenAccess.Query.dll is renamed to Telerik.OpenAccess.35.Extensions.dll
  • Telerik.OpenAccess.40.dll is renamed to Telerik.OpenAcces.40.Extensions.dll
  • There is separation of the Win and Web UI into separate assemblies out of Telerik.OpenAccess.dll. These are Telerik.OpenAccess.Web.dll and Telerik.OpenAccess.Windows.dll assemblies.

The IObjectScope.GetOqlQuery<T>() method

When a query is expected to return instances of a known type that delivers additional functionality and optimization. Such queries can be realized by using the generic query type Query<T>. An instance of that class can be achieved from the IObjectScope.GetOqlQuery<T>() method which accepts the query string as a parameter. If no string is passed, the method returns a Query<T> object that will collect all instances of the required persistence-capable type when executed. The Query<T> class has ExecuteList(), ExecuteBindingList() and ExecuteEnumerable() methods. Each of them executes the query and returns the same objects wrapped in a different type of collection:

C# Copy Code
RadGridCustomers.DataSource = scope.GetOqlQuery<Customer>().ExecuteBindingList();  
VB .NET Copy Code
RadGridCustomers.DataSource = scope.GetOqlQuery(Of Customer)().ExecuteBindingList()

This method works with .NET Framework 2.0 and above. 

The IObjectScope.Extent<T>() method

Another way of retrieving is using the Extent<T>() generic method of the object scope. It provides an instance that implements the IQueryable interface and it is ready for binding to controls:

C# Copy Code
RadGridCustomers.DataSource = scope.Extent<Customer>();
VB .NET Copy Code
RadGridCustomers.DataSource = scope.Extent(Of Customer)()

The Extent<T>() is also usable in Linq queries:

C# Copy Code
var result = from b in objectScope.Extent<Buyer>()
            where b.Name ==
select b;

VB .NET Copy Code
Dim result = From b In objectScope.Extent(Of Buyer)() _
             Where b.Name = "Peter" _
             Select b

Extent<T>() is an extension method which takes place in the Telerik.OpenAccess.Query.dll library and requires .NET Framework 3.5 or newer. 

Getting the Root Type of an IQuery instance

When the non-generic IObjectScope.GetOqlQuery() method is used, it returns an IQuery instance which does not have any persistence-capable type specified for the retrieved objects. The IQuery.RootType property gets the root type of the query result, when the query returns only instances of persistence-capable classes. The returned type is the common type of all returned persistence-capable instances (enhanced classes). If no common type exists (for example by use of a projection), null is returned.