Bundt Programmer's Guide · Bundt Programmer's Interface version 1.0.1.0

Navigate Objects, References and Values

The following example shows how to navigate the network of objects, references and values in an instance model.

Navigation allows us to retrieve objects or values that are directly or indirectly connected to a starting object via references, using very compact code. To navigate a model we use navigation expressions, which are strings of dot-separated identifiers referring to attribute, semi-association or role names. An exclamation mark may be used to pick the first element in a collection.

To execute this code, you will need a reference to the ModellingEngine library.

using Incipit.Bundt.ModellingEngine;

//load an instance model.
var imo = new FileModelPersister("C:\\Temp\\MyModel.bundt-im").LoadInstanceModel();

//get object for the city of Paris.
var obParis = imo.FindObject("paris");

//get Paris' mayor.
var obParisMayor = obParis.NavigateToObject("Mayor");

//get Paris' mayor's last name.
var strLastName = obParis.NavigateToValue("Mayor.LastName").ContentText;

//get the population of the country where Paris' mayor's place of birth is located.
var decPopulation = obParis.NavigateToValue("Mayor.PlaceOfBirth.Country.Population").ContentNumber;

//get one of the universities where Paris' mayor studied.
var obUniversity = obParis.NavigateToObject("Mayor.AcademicDegrees!.University");

In line 4, we load an instance model. For the sake of this example, we will assume that this model contains many objects of types City, Person, University and Country, with multiple attributes and associations connecting them.

In line 7, we call FindObject to pick the object of type City representing the city of Paris. This will be our starting object for the navigation examples below.

In line 10, we retrieve an object representing the Paris' mayor by calling NavigateToObject and passing the simple navigation expression "Mayor". We assume here that the City class has a Mayor semi-association to Person.

In line 13, we retrieve the value for Paris' mayor's last name by calling NavigateToValue and passing the navigation expression "Mayor.LastName". We assume here that, in addition to the Mayor semi-association from City to Person, the latter has a LastName attribue of type Text.

In line 16, we retrieve the population of the country where Paris' mayor's place of birth is located. We do this by calling NavigateToValue and passing the navigation expression "Mayor.PlaceOfBirth.Country.Population". This navigates first from the Paris object to its mayor, then to his/her place of birth, then to the country where this is located, and finally to the Population value.

Finally, in line 19 we retrieve one of the universities where Paris' mayor studied. We do this by calling again NavigateToObject and passing the navigation expression "Mayor.AcademicDegrees!.University". This navigates first from the Paris object to its mayor, then to the collection of his/her academic degrees, and then selects the first in the collection. Then, it navigates to the University object corresponding to this degree.


Contents distributed under a Creative Commons Attribution 4.0 International License · About · Terms of Use · Contact Us · last updated on 08 October 2020