The requested page is not available for the requested platform. You are viewing the content for Default platform.

CalculatedPersistentAliasAttribute Class

Applied to a business class. Allows you to dynamically configure a persistent alias for the target business class' property.

Namespace: DevExpress.ExpressApp.Xpo

Assembly: DevExpress.ExpressApp.Xpo.v18.2.dll


[AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = false)]
public class CalculatedPersistentAliasAttribute :
<AttributeUsage(AttributeTargets.Class, AllowMultiple:=True, Inherited:=False)>
Public Class CalculatedPersistentAliasAttribute
    Inherits Attribute


Non-persistent calculated properties for which filtering and sorting should be performed on the database level can be implemented via the PersistentAliasAttribute. The PersistentAlias attribute takes a single parameter which specifies the expression used to calculate the property's value on the database server side. A persistent alias must be specified in code as the attribute's parameter. However, in certain scenarios, the property may be required to have a configurable persistent alias, and it must be possible to configure it in a deployed application by an administrator. In this instance, the CalculatedPersistentAliasAttribute attribute should be used.

The CalculatedPersistentAliasAttribute contains two properties initialized via the attribute's constructor. The first parameter specifies the property name for which you would like to set up a persistent alias. The second parameter specifies the property which returns the alias' expression. The property which returns the alias' expression can return different expressions based on a specific rule. For example, you can implement logic which loads the alias expression from a configuration file which can be customized by a system administrator.

Note that the CalculatedPersistentAliasAttribute attribute is initialized at the application startup, while the application is being set up. So, if you want to change the value returned by the property which specifies the alias expression, this should be done while the application is being initialized, for example, in a module's constructor.

The following code snippet illustrates use of the CalculatedPersistentAliasAttribute. The Product class contains the calculated ProductName property, which has a configurable persistent alias:


A complete sample project is available in the DevExpress Code Examples database at

[CalculatedPersistentAlias("ProductName", "ProductNameAlias"), DefaultClassOptions]
public class Product : BaseObject {
    public Product(Session session) : base(session) { }

    private static string productNameFormat = "{Manufacturer} {Model}";
    private static string productNameAlias = "concat(Manufacturer, Model)";

    public string ProductName {
        get { return ObjectFormatter.Format(
            productNameFormat, this, EmptyEntriesMode.RemoveDelimiterWhenEntryIsEmpty ); }
    public static string ProductNameAlias {
        get { return productNameAlias; }            
    public static void SetProductNameFormat(string productNameFormat, string productNameAlias) {
        if(!string.IsNullOrEmpty(productNameFormat)) {
            Product.productNameFormat = productNameFormat;
        if(!string.IsNullOrEmpty(productNameAlias)) {
            Product.productNameAlias = productNameAlias;

    public string Manufacturer {
        get { return GetPropertyValue<string>("Manufacturer"); }
        set { SetPropertyValue<string>("Manufacturer", value); }
    public string Model {
        get { return GetPropertyValue<string>("Model"); }
        set { SetPropertyValue<string>("Model", value); }
    public string Revision {
        get { return GetPropertyValue<string>("Revision"); }
        set { SetPropertyValue<string>("Revision", value); }

Note that a property which returns the persistent alias' expression must be declared as public and static (Public and Shared in VB).

The persistent alias' value is initialized from the application's configuration file in a module's constructor:

public sealed partial class CalculatedAliasModule : ModuleBase {
    public CalculatedAliasModule() {


In addition, it is required to override the ModuleBase.CustomizeTypesInfo method in the following manner:

using DevExpress.ExpressApp.Xpo;
// ...
public override void CustomizeTypesInfo(ITypesInfo typesInfo) {

Note that two business classes from the Business Class Library use the CalculatedPersistentAliasAttribute attribute. The Person class uses this attribute to configure the format of the calculated FullName property, and the Address class uses this attribute to configure the calculated FullAddress property. To learn how to configure the format of these properties, refer to the How to: Change the Format Used for the FullAddress and FullName Properties topic.




See Also