A newer version of this page is available. Switch to the current version.

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.v18.2.dll


[AttributeUsage(AttributeTargets.Property, Inherited = true)]
public sealed class PersistentAliasAttribute :
<AttributeUsage(AttributeTargets.Property, Inherited:=True)>
Public NotInheritable Class PersistentAliasAttribute
    Inherits Attribute


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;
   public int Qty;
   public decimal Discount;

   public decimal ExtendedPrice {
      get { return Convert.ToDecimal(EvaluateAlias("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;

// ...
private string 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"


See Also