CalculatedAttribute Class
Applies to business class properties. Specifies an expression used to calculate the target property value.
Namespace: DevExpress.ExpressApp.DC
Assembly: DevExpress.ExpressApp.v24.2.dll
NuGet Package: DevExpress.ExpressApp
Declaration
Remarks
Use the CalculatedAttribute
to specify an expression used to calculate the value of a calculated property.
In an EF Core business class, a property decorated with the CalculatedAttribute
works as a regular property in all data access modes. Note that for an EF Core class property, the CalculatedAttribute
has the same effect as the PersistentAliasAttribute.
In an XPO business class, a decorated property’s calculated value is correctly displayed only in the Data View mode.
Important
It is not recommended to use the CalculatedAttribute
in XPO business classes. Use the PersistentAlias attribute instead.
The following code snippet uses the CalculatedAttribute
:
using DevExpress.ExpressApp.DC;
// ...
public class Person : BaseObject {
// ...
public virtual String FirstName { get; set; }
public virtual String LastName { get; set; }
[Calculated("Concat(FirstName, ' ', LastName)")]
public String FullName {
get {
get { return EvaluateAlias<String>(); }
}
}
}
// Make sure that you use options.UseChangeTrackingProxies() in your DbContext settings.
The expression specified through the CalculatedAttribute.Expression parameter is calculated on the database server side. The expression can reference persistent properties, other calculated properties, or criteria functions that can be executed by the database server through SQL.