Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

Calculated properties determine their value from an Expressions or a lambda.

Calculated properties

An application can add calculated properties to a class or layout. If you're not already familiar with expressions, please see the Expressions for more information.

Use the ClassBuilder.Add.CalculatedProperty(...) or one of the overloads to create a new calculated property.

See Metadata Delegate Expressions for many examples of creating calculated properties.

Value-generation Frequency

This setting applies to all properties (persistent and calculated) but it is especially useful for calculated properties.

An application can indicate when Quino should recalculate the value for a property.

  • Default: For persistent properties, the default is Cached; for calculated properties, it's Volatile.

  • Cached: The value is cached on first retrieval. It is only refreshed when the object is reloaded.

  • Volatile: The value is recalculated on each retrieval.

If an application has calculated properties that are expensive to calculate but whose value doesn't often change, it can change the value-generation frequency to Cached in order to speed up display in the UI or reports.

A product can put as much logic/work as it needs into a calculated property. In the next case, we use the ValueGenerationFrequency to cache the value.

person.Add
  .CalculatedProperty(("TimeStuff", MetaType.Integer)
  .ValueExpression(...)
  .Configure(x => x.SetValueGenerationFrequency(ValueGenerationFrequency.Cached));
//...

private int GetTimeStuff(Person person)
{
  foreach (var t in person.TimeEntries)
  {
    var project = t.Project;
    var lead = project.Lead;
    var address = lead.Address;
    
    if (lead.Active)
    {
      return address.ZipCode;
    }

    // Otherwise, do other stuff...
  }
};

  • No labels