🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
OCLOperators PSExpression Refresh
This page was created by Stephanie on 2025-01-09. Last edited by Wikiadmin on 2026-07-29.

PSExpression_Refresh evaluates the database-oriented expressions in the current ViewModel so you can update PSExpression values after an EAL action without loading the expression's result objects into the client.

Use it in an EAL action when a ViewModel contains columns whose names begin with PSExpression_, particularly for database aggregates such as counts, sums, minimums, and maximums.

Syntax

selfVM.PSExpression_Refresh()

Call the operator on selfVM, the current ViewModel instance. It takes no arguments.

What it refreshes

PSExpression_Refresh() finds every ViewModel column that is an IsPSExpression column and evaluates its expression through the OCL persistence-storage service (OCL-PS).

A ViewModel column becomes an IsPSExpression column when its name starts with PSExpression_. For example, these columns are included:

  • PSExpression_OrderCount
  • PSExpression_TotalAmount
  • PSExpression_MaxValue

A column named OrderCount is not included. Rename it to PSExpression_OrderCount if it is intended to be evaluated by this operator.

The operator evaluates all qualifying columns in the current ViewModel. It does not target one named column.

Why use it

Normal OCL evaluation can lazily fetch objects as an expression navigates associations. For expressions that consider hundreds, thousands, or more objects, this can mean that many objects are fetched before an aggregate is calculated.

A PSExpression uses OCL-PS to interpret the expression for persistence storage. This is appropriate when you need a database to do work such as finding a value in a very large table or calculating an aggregate over a large result set.

For example, an order total can be calculated in the database and returned as a value for a ViewModel field, rather than fetching every matching Order object so the client can perform the sum.

You can also use SqlPassthrough in a PSExpression when the required operation is expressed as SQL. SqlPassthrough sends the supplied SQL to the database; PSExpression_Refresh() causes the qualifying ViewModel expression to be evaluated. The refresh operator itself is not a raw-SQL command.

Configure and refresh a PSExpression

  1. In the ViewModel, add a column for the value you want to display.
  2. Name the column with the PSExpression_ prefix. For example, use PSExpression_OrderCount.
  3. Enter an expression that produces the value required by the column. Use an aggregate when you need one database result rather than a collection of objects.
  4. Bind the column in the ViewModel UI where the value should be shown.
  5. In the EAL action that changes the underlying data, call selfVM.PSExpression_Refresh() after the change.

The refresh re-evaluates every PSExpression column and updates their ViewModel values for the UI.

Example: refresh an aggregate after a change

Assume a ViewModel displays the number of Orders belonging to the current Customer. Add a column named PSExpression_OrderCount and give it an expression equivalent to the following:

Order.allInstances->select(o | o.Customer = self)->size

After an action creates an Order for that Customer, refresh the PSExpressions:

let newOrder = Order.Create() in
  (newOrder.Customer := self;
   selfVM.PSExpression_Refresh())

The refresh evaluates PSExpression_OrderCount and writes the resulting count to the ViewModel column. This pattern is useful when the count must reflect an action immediately and the number of Orders can be large.

Use SqlPassthrough where SQL is required

A PSExpression can contain SqlPassthrough when you need database-specific SQL, such as a stored-procedure call or SQL aggregation that is unsuitable for ordinary OCL. SqlPassthrough starts with a class and declares the type or types returned by the SQL expression.

For example, a PSExpression may use SQL to return aggregate values, while PSExpression_Refresh() evaluates that expression and exposes the result through the associated ViewModel column. Keep assumptions about the physical database schema deliberate and limited: direct SQL trades database independence for direct access to database capabilities.

For syntax, parameter handling, and tuple results, see Documentation:OCLOperators sqlpassthrough. For the broader PSExpression model and OCL-PS behavior, see Documentation:PSExpression , or how to do things in the DB from MDriven.

Choose the correct refresh operation

Requirement Use What it does
Re-evaluate all PSExpression_ columns in the current ViewModel selfVM.PSExpression_Refresh() Evaluates the ViewModel's IsPSExpression columns through OCL-PS.
Check whether objects have changed on the persistence server and invalidate stale client objects Refresh Synchronizes object freshness between clients and the persistence server; it does not specifically evaluate PSExpression columns.
Run the ViewModel Seeker search again ReQuery Re-executes the current search logic and updates vSeekerResult.

Practical guidance

  • Use a PSExpression for large-set aggregates such as count, sum, max, min, or average.
  • Call PSExpression_Refresh() after an action when the displayed database-derived value must reflect the action.
  • Do not expect this operator to refresh ordinary ViewModel columns; only IsPSExpression columns are evaluated.
  • Do not use Refresh as a substitute when the requirement is to calculate PSExpression values.
  • Use ReQuery when the requirement is to update a Seeker result set, not a database-derived ViewModel field.

See also