🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
Accessing objects and navigating meta-levels in code
This page was created by Lars.olofsson on 2019-08-14. Last edited by Wikiadmin on 2026-07-29.

You can test whether a single-valued runtime association has a related object by reading its IObjectReference.ObjectInstance.asObject; this page is for developers working with MDriven Framework runtime objects.

Check a single link

A single link at runtime is represented by an IObjectReference on an IObject. The reference represents the association end and can point to another runtime object.

Use the following check when you have obtained a member that represents a single link:

if ((destinationMember as IObjectReference).ObjectInstance.asObject == null)
{
  // No object is connected at this link end.
}

For example, if an object has an optional single association named Customer, this condition is true when the current object has no Customer connected through that association.

Understand ObjectInstance and asObject

Do not test ObjectInstance itself for null.

ObjectInstance is always non-null because it is the object that holds information about the link end. When no object is connected, that value can be a nullObjectImpl, which is still an object. The asObject value is the value to test when you need to determine whether an object exists at the other end of the link.

Expression Meaning
(destinationMember as IObjectReference).ObjectInstance The runtime holder for the link end. It is always non-null.
(destinationMember as IObjectReference).ObjectInstance.asObject The related runtime object, or null when the link has no object at the other end.

Use this only for a single-valued association

This pattern applies when destinationMember is a member implemented as an IObjectReference. Do not use it as a general null check for every member: a member that is not a single link does not represent the same runtime shape.

Before applying the pattern, verify that the member you obtained is the intended single association end. In the example above, the cast to IObjectReference identifies the runtime representation expected by the code.

Runtime objects and ViewModels

This check concerns runtime objects and their links. A ViewModel can expose values and related information from the main model, but its display structure is a separate concern. For example, whether related objects are available in a nested ViewModel depends on how that ViewModel is structured; see Cursored or Full Tree for the difference between cursored and full-tree access.

See also