Telerik OpenAccess Classic

Telerik OpenAccess ORM Send comments on this topic.
How to: Execute a Query that Returns a Primitive Type
Programmer's Guide > OpenAccess ORM Classic (Old API) > OpenAccess Tasks > Querying a Data Model > How to: Execute a Query that Returns a Primitive 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 topic describes how to define and execute queries that return a primitive type.

 

The following code demonstrates how queries against an OpenAccess object scope return primitive int values: 

C# Copy Code
//OQL
private static void OQLQueryReturningIntPrimitiveType(IObjectScope scope)
{
    Console.WriteLine(
"\n### Count of all employees###");
    
string queryString =
        
"select emp.EmployeeID from EmployeeExtent AS emp ";
               
    Query<
int> oqlQuery = scope.GetOqlQuery<int>(queryString);
    QueryResultList<
int> result = oqlQuery.ExecuteList();
}

//Linq
private static void LinqQueryReturningIntPrimitiveType(IObjectScope scope)
{
   IObjectScopeQuery<
int> result = from e in scope.Extent<Employee>()
                                   select e.EmployeeID;
      
}
VB .NET Copy Code
'OQL
Private Shared Sub OQLQueryReturningStringPrimitiveType(scope As IObjectScope)
 Dim queryString As String = "select emp.firstName from EmployeeExtent AS emp "
 Dim oqlQuery As Query(Of String) = scope.GetOqlQuery(Of String)(queryString)
 Dim result As QueryResultList(Of String) = oqlQuery.ExecuteList()
 End Sub
'Linq
Private Shared Sub LinqQueryReturningIntPrimitiveType(scope As IObjectScope)
 Dim result As IObjectScopeQuery(Of Integer) = From e In scope.Extent(Of Employee)() _
                                               Select e.EmployeeID
End Sub

 

The following code samples demonstrate how queries that return primitive string value are executed using OpenAccess-related syntax.

C# Copy Code
//OQL
private static void OQLQueryReturningStringPrimitiveType(IObjectScope scope)
{
  
string queryString = "select emp.firstName from EmployeeExtent AS emp ";
  Query<
string> oqlQuery = scope.GetOqlQuery<string>(queryString);
  QueryResultList<
string> result = oqlQuery.ExecuteList();
}

//Linq
private static void LinqQueryReturningStringPrimitiveType(IObjectScope scope)
{
   IObjectScopeQuery<
string> result = from e in scope.Extent<Employee>()
                                      select e.FirstName;
          
}
VB .NET Copy Code
'OQL
Private Shared Sub OQLQueryReturningStringPrimitiveType(scope As IObjectScope)
 Dim queryString As String = "select emp.firstName from EmployeeExtent AS emp "
 Dim oqlQuery As Query(Of String) = scope.GetOqlQuery(Of String)(queryString)
 Dim result As QueryResultList(Of String) = oqlQuery.ExecuteList()
End Sub

'Linq
Private Shared Sub LinqQueryReturningStringPrimitiveType(scope As IObjectScope)
 Dim result As IObjectScopeQuery(Of String) = From e In scope.Extent(Of Employee)() _
                                             Select e.FirstName
End Sub