OCLOperators value
No edit summary
No edit summary
Line 21: Line 21:
  Product.allinstances->collect(i|i.Price.Value)->sum
  Product.allinstances->collect(i|i.Price.Value)->sum
This will ensure a value is always returned by the expression, either when there are no product instances or the product price is not set for all instances.
This will ensure a value is always returned by the expression, either when there are no product instances or the product price is not set for all instances.
[[Category:OCLOperators]]

Revision as of 05:55, 6 January 2025

Returns the the non-null value of a simple nullable type.

Expression Result
int? with the value null 0

The value of the current nullable object is returned if it has been assigned a valid underlying value - otherwise, 0 is returned.

Some expressions may require a non-null value and yet your attribute is a nullable type. A scenario like this is catered for in the MDriven OCL expressions.

.Value is available for all number types including Integer, Decimal, Double, and Int64.

For example:

getting value for nullable type

To calculate the Total Price of all products use:

Product.allinstances.Price->sum.Value

or:

Product.allinstances->collect(i|i.Price.Value)->sum

This will ensure a value is always returned by the expression, either when there are no product instances or the product price is not set for all instances.

This page was edited 67 days ago on 01/20/2025. What links here