Telerik OpenAccess Classic

Telerik OpenAccess ORM Send comments on this topic.
The Alias Property
See Also
Programmer's Guide > OpenAccess ORM Classic (Old API) > Telerik OpenAccess ORM OQL Reference > OQL - Object Query Language > The Select Statement > The Alias Property

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 [Persistent] attribute is used to declare a class, interface, or struct as persistence capable. The [Persistent] attribute has a number of modifiable properties to define the characteristics of a persistent type (Refer to OpenAccess .NET Programmer's Guide for more information). One of these properties is the Alias property, which has been described in this topic.

The Alias property specifies an alternative name, an alias, for the name of a persistent type. By default, the short name of the type without its namespace is used.

Alias names are convenient for specifying classes in OQL queries. An alias can be specified as follows:

C# Copy Code
[Persistent(Alias="Addr")]
public class Address
{
 
// . . .
}

In the example given above the [Persistent] attribute, along with an Alias "Addr", is applied to the Address class.

Specifying Alias names is useful in the following scenarios:

  • Two classes with the same name in two different namespaces. For e.g. If we have an Employee class in two different namespaces, the only way to specify the right type in a query is by using the Alias property:
    C# Copy Code
    Type your example code here. It will be automatically colorized when you switch to Preview or build the help system.
    VB.NET Copy Code
    Type your example code here. It will be automatically colorized when you switch to Preview or build the help system.
    Now, if you want to query the Employee class in the Project A namespace, you should write the query as:
    OQL Copy Code
    SELECT * FROM ProjectAEmployeeExtent
    The above statement will query the Employee class and will return all the Employee objects in the Project A namespace. Similarly, if you want to query the Employee class in the Project B namespace, you should write the query as:
    OQL Copy Code
    SELECT * FROM ProjectBEmployeeExtent
    The above statement will query the Employee class and will return all the Employee objects in the Project B namespace. Therefore, using the Alias property helps you to specify the right type in a query.
  • An alias is also useful when you want to rename your classes without having to change the queries. For e.g., If we want to rename the Address class (which has been specified an alias "Addr" above) to EmployeeAddress, we can do so without having to change the query, i.e., the queries can yet be written as:
    OQL Copy Code
    SELECT * FROM %AliasName%Extent
    In our example the %AliasName% will be replaced by what ever your allies name is:
    OQL Copy Code
    SELECT * FROM AddrExtent
    The alias can also be applied later, that means in our Address renaming scenario you can change the Address class name to EmployeeAddress and apply the alias "Address" to the class:
    C# Copy Code
    public class Address
    {
     
    // . . .
    }
    [Persistent(Alias="Address")]
    public class EmployeeAddress
    {
     
    // . . .
    }
    In this case too the queries will remain the same as before, since the earlier class name and the alias name are the same, i.e., Address.
Once the alias name is specified the user needs to use the alias name in a query, even when there is just one class. For e.g., if we have specified the following:
C# Copy Code
[Persistent(Alias="Emp")]
public class Employee
{
 
// . . .
}

You need use the alias name Emp in any query on the above Employee class. If we specify the class name (Employee) in a query (for e.g., SELECT * FROM EmployeeExtent) we will get an exception like: No class found for extent "EmployeeExtent".

Therefore, whenever we need to query the above Employee class we will have to specify the alias name in the query like:

OQL Copy Code
SELECT * FROM EmpExtent

See Also