Skip to main content
A newer version of this page is available. .
.NET Framework 4.5.2+

PersistentAliasAttribute Class

Indicates that a property is not persistent and its value is calculated based upon the values of a specific field(s).

Namespace: DevExpress.Xpo

Assembly: DevExpress.Xpo.v21.1.dll

NuGet Package: DevExpress.Xpo

Declaration

[AttributeUsage(AttributeTargets.Property, Inherited = true)]
public sealed class PersistentAliasAttribute :
    Attribute

Remarks

The expression to be evaluated can be passed as the constructor’s parameter or specified via the PersistentAliasAttribute.AliasExpression property. You can use both persistent and non-persistent fields to specify the expressions. The expression is evaluated at the server side when only persistent properties are used. When a non-persistent property is referred, XPO extracts a persistent part from an expression, sends it to the database server, and processes the rest on the client. Note that this is only possible when an operation involves object loading and won’t work in XPView.

The following code shows how to define a property as non-persistent and calculate its value based upon the values of specific persistent fields. The ExtendedPrice property is marked as a non-persistent, using the PersistentAliasAttribute attribute. The expression to evaluate the property’s value is specified as the attribute’s parameter. In addition, the property’s getter evaluates this expression using the XPBaseObject.EvaluateAlias method.

using DevExpress.Xpo;

public class Order : XPObject {
   public Order() {}
   public decimal UnitPrice {
       get { return fUnitPrice; }
       set { SetPropertyValue(nameof(UnitPrice), ref fUnitPrice, value); }
   }
   decimal fUnitPrice;

   public int Qty {
       get { return fQty; }
       set { SetPropertyValue(nameof(Qty), ref fQty, value); }
   }
   int fQty;

   public decimal Discount {
       get { return fDiscount; }
       set { SetPropertyValue(nameof(Discount), ref fDiscount, value); }
   }
   decimal fDiscount;


   [PersistentAlias("UnitPrice*Qty*(1-Discount)")]
   public decimal ExtendedPrice {
      get { return Convert.ToDecimal(EvaluateAlias(nameof(ExtendedPrice))); }
   }
}

The following example shows how to use the PersistentAliasAttribute to implement a public read-only property exposing a value of the private persistent property. The expression passed in the PersistentAliasAttribute class constructor specifies the name of the field which stores the value at runtime. The field is decorated with the PersistentAttribute whose PersistentAttribute.MapTo property holds the name of the data store column where the field’s value is stored.

using DevExpress.Xpo;

// ...
[Persistent("DefaultAddress")]
private string mDefaultAddress;

[PersistentAlias(nameof(mDefaultAddress))]
public string DefaultAddress {
    get {
        return mDefaultAddress;
    }
}

Note that while a criteria expression can return an object reference, this is not supported in all scenarios. Returning an object reference by directly referencing a property, as in the following code snippet, is fully supported.

“Iif(Part is null, MyCustOrderLine.Part, Part)”

In this code snippet, the Part object, which the Part or MyCustOrderLine.Part property references, is returned correctly. However, retrieving reference properties from functions is not supported. So, the following expression does not work.

“Iif(Part is null, MyCustOrderLine, MyCustOrderLine2).Part”

Inheritance

Object
Attribute
PersistentAliasAttribute
See Also