You can add properties into the Entity class that are not in the actual database. These
custom DataFields usually have code that determines there value. When that code involves
a numeric calculation, add the CalculationDescriptorAttribute. That tells the user interface
how to make the DataField's value change interactively as the user edits other DataFields
involved in the calculation.
Describe the calculation in the Expression property using a hybrid syntax of C# and VB.
Here are CalculationDescriptorAttributes associated with the Product Entity class. Notice
that these properties are in the Entity class itself, not in the Entity Metadata class.
The Entity Metadata class can still host CalculationDescriptorAttributes whose calculated
value is determined by a View in the database.
[EntityDAOType(typeof(ProductDAO))]
[MetadataType(typeof(ProductMetadata))]
public partial class Product : DESDA.ICustomizeDataField
{
[DESDA.CalculationDescriptor("If (Not Discontinued) Then {UnitPrice * UnitsInStock} Else novalue")]
public decimal ValueOfStock
{
get
{
if (!Discontinued)
if (UnitPrice.HasValue && UnitsInStock.HasValue)
return UnitPrice.Value * UnitsInStock.Value;
return 0.0M;
}
}
[DESDA.CalculationDescriptor("if (!Discontinued) then {UnitPrice * (UnitsInStock + UnitsOnOrder)} else novalue")]
public decimal ValueOfAvailableUnits
{
get
{
if (!Discontinued)
{
int vStock = 0;
if (UnitsInStock.HasValue)
vStock = UnitsInStock.Value;
if (UnitsOnOrder.HasValue)
vStock = vStock + UnitsOnOrder.Value;
if (UnitPrice.HasValue)
return UnitPrice.Value * vStock;
}
}
}
}
The Source Code Browser shows completed DataAnnotations. The CalculationDescriptorAttributes
have been highlighted.
Open the Source Code Browser (C# only)